Retrieve metadata for files specified via path or via file id.

If the files are specified via path, the returned dribble will include a path column. To add path information to any dribble that lacks it, use drive_reveal(), e.g., drive_reveal(d, "path"). If you want to list the contents of a folder, use drive_ls(). For general searching, use drive_find().

If you want to get a file via path and it's not necessarily on your My Drive, you may need to specify the shared_drive or corpus arguments to search other collections of items. Read more about shared drives.

drive_get(
  path = NULL,
  id = NULL,
  shared_drive = NULL,
  corpus = NULL,
  verbose = deprecated(),
  team_drive = deprecated()
)

Arguments

path

Character vector of path(s) to get. Use a trailing slash to indicate explicitly that a path is a folder, which can disambiguate if there is a file of the same name (yes this is possible on Drive!). If path appears to contain Drive URLs or is explicitly marked with as_id(), it is treated as if it was provided via the id argument.

id

Character vector of Drive file ids or URLs (it is first processed with as_id()). If both path and id are non-NULL, id is silently ignored.

shared_drive

Anything that identifies one specific shared drive: its name, its id or URL marked with as_id(), or a dribble. The value provided to shared_drive is pre-processed with as_shared_drive(). Read more about shared drives.

corpus

Character, specifying which collections of items to search. Relevant to those who work with shared drives and/or Google Workspace domains. If specified, must be one of "user", "drive" (requires that shared_drive also be specified), "allDrives", or "domain". Read more about shared drives.

verbose

[Deprecated] This logical argument to individual googledrive functions is deprecated. To globally suppress googledrive messaging, use options(googledrive_quiet = TRUE) (the default behaviour is to emit informational messages). To suppress messaging in a more limited way, use the helpers local_drive_quiet() or with_drive_quiet().

team_drive

[Deprecated] Google Drive and the Drive API have replaced Team Drives with shared drives.

Value

An object of class dribble, a tibble with one row per item.

Special considerations for paths

Note that Google Drive does NOT behave like your local file system:

  • File and folder names need not be unique, even at a given level of the hierarchy. A single name or file path can be associated with multiple files (or zero or exactly one).

  • A file can have more than one direct parent. This implies that a single file can be represented by multiple paths.

Bottom line: Do not assume there is a one-to-one relationship between file name or path and a Drive file or folder. This implies the length of the input (i.e. the number of input paths or the number of rows in a dribble) will not necessarily equal the number rows in the output.

See also

Wraps the files.get endpoint and, if you specify files by name or path, also calls files.list:

Examples

# get info about your "My Drive" root folder
drive_get("~/")
#> # A dribble: 1 x 4
#>   name     path  id                  drive_resource   
#>   <chr>    <chr> <chr>               <list>           
#> 1 My Drive ~/    0AO_RMaBzcP63Uk9PVA <named list [30]>
# the API reserves the file id "root" for your root folder
drive_get(id = "root")
#> # A dribble: 1 x 3
#>   name     id                  drive_resource   
#> * <chr>    <chr>               <list>           
#> 1 My Drive 0AO_RMaBzcP63Uk9PVA <named list [30]>
drive_get(id = "root") %>% drive_reveal("path")
#> # A dribble: 1 x 4
#>   name     path  id                  drive_resource   
#>   <chr>    <chr> <chr>               <list>           
#> 1 My Drive ~/    0AO_RMaBzcP63Uk9PVA <named list [30]>

if (FALSE) {
# The examples below are indicative of correct syntax.
# But note these will generally result in an error or a
# 0-row dribble, unless you replace the inputs with paths
# or file ids that exist in your Drive.

# multiple names
drive_get(c("abc", "def"))

# multiple names, one of which must be a folder
drive_get(c("abc", "def/"))

# query by file id(s)
drive_get(id = "abcdefgeh123456789")
drive_get(as_id("abcdefgeh123456789"))
drive_get(id = c("abcdefgh123456789", "jklmnopq123456789"))

# apply to a browser URL for, e.g., a Google Sheet
my_url <- "https://docs.google.com/spreadsheets/d/FILE_ID/edit#gid=SHEET_ID"
drive_get(my_url)
drive_get(as_id(my_url))
drive_get(id = my_url)

# access the shared drive named "foo"
# shared_drive params must be specified if getting by path
foo <- shared_drive_get("foo")
drive_get(c("this.jpg", "that-file"), shared_drive = foo)
# shared_drive params are not necessary if getting by id
drive_get(as_id("123456789"))

# search all shared drives and other files user has accessed
drive_get(c("this.jpg", "that-file"), corpus = "allDrives")
}