Get Drive files by path or id
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
variable. 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()
.
Note: Team Drives are only available to users of certain enhanced Google services, such as G Suite Enterprise, G Suite Business, or G Suite for Education.
drive_get( path = NULL, id = NULL, team_drive = NULL, corpus = NULL, verbose = TRUE )
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
|
id |
Character vector of Drive file ids or URLs (it is first processed
with |
team_drive |
Anything that identifies one specific Team Drive: its name,
its id or URL marked with |
corpus |
Character, specifying the search collection. Only relevant in
the Team Drives context. If specified, must be one of |
verbose |
Logical, indicating whether to print informative messages
(default |
An object of class dribble
, a tibble with one row per item.
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.
Wraps the files.get
endpoint and, if you specify files by name or
path, also calls files.list
:
## Not run: ## get info about your "My Drive" root folder drive_get("~/") ## the API reserves the file id "root" for your root folder drive_get(id = "root") drive_get(id = "root") %>% drive_reveal("path") ## 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 Team Drive named "foo" ## team_drive params must be specified if getting by path foo <- team_drive_get("foo") drive_get(c("this.jpg", "that-file"), team_drive = foo) ## team_drive params are not necessary if getting by id drive_get(as_id("123456789")) ## search all Team Drives and other files user has accessed drive_get(c("this.jpg", "that-file"), corpus = "all") ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.