Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drive_download() is uncooperative re: downloading into a folder #250

Open
jennybc opened this issue Apr 2, 2019 · 2 comments
Open

drive_download() is uncooperative re: downloading into a folder #250

jennybc opened this issue Apr 2, 2019 · 2 comments
Labels
feature folder 📁 future

Comments

@jennybc
Copy link
Member

@jennybc jennybc commented Apr 2, 2019

I wish drive_download(WHATEVER, path = "pre_existing_local_folder/") would download WHATEVER into pre_existing_local_folder/WHATEVER instead of:

Error: Path exists and overwrite is FALSE
@jennybc jennybc added the feature label Apr 26, 2019
@reblake
Copy link

@reblake reblake commented Jan 26, 2022

I share the same wish!
I try to download multiple files into an empty folder that already exists using:
walk(file_list$id, ~ drive_download(as_id(.x), overwrite = TRUE, path = here("raw_data_files/")))

and instead receive
Error in curl::curl_fetch_disk(url, x$path, handle = handle) : Failed to open file /home/username/my-git-repo/raw_data_files.

@h-a-graham
Copy link

@h-a-graham h-a-graham commented Jun 16, 2022

+1 for this feature! In the meantime I found this quite helpful in case anyone stumbles on this issue:

library(googledrive)

drive_down_to_dir <- function(x, dir, overwrite = TRUE, ...) {
  if (!dir.exists(dir))
    dir.create(dir)
  purrr::pmap(x, function(name, id, drive_resource, ...) {
    drive_download(as_id(id), file.path(dir, name),
                   overwrite = overwrite, ...)
  },
  ...)
}

file_drib <- drive_examples_remote()[1:3,]

drive_down_to_dir(file_drib, "new_folder")
#> File downloaded:
#> • 'chicken_doc' <id: 1X9pd4nOjl33zDFfTjw-_eFL7Qb9_g6VfVFDp1PPae94>
#> Saved locally as:
#> • 'new_folder/chicken_doc.docx'
#> File downloaded:
#> • 'chicken_sheet' <id: 1SeFXkr3XdzPSuWauzPdN-XnaryOYmZ7sFiUF5t-wSVU>
#> Saved locally as:
#> • 'new_folder/chicken_sheet.xlsx'
#> File downloaded:
#> • 'chicken.csv' <id: 1VOh6wWbRfuQLxbLg87o58vxJt95SIiZ7>
#> Saved locally as:
#> • 'new_folder/chicken.csv'
#> [[1]]
#> # A dribble: 1 × 4
#>   name        local_path                  id                      drive_resource
#>   <chr>       <chr>                       <drv_id>                <list>        
#> 1 chicken_doc new_folder/chicken_doc.docx 1X9pd4nOjl33zDFfTjw-_e… <named list>  
#> 
#> [[2]]
#> # A dribble: 1 × 4
#>   name          local_path                    id                  drive_resource
#>   <chr>         <chr>                         <drv_id>            <list>        
#> 1 chicken_sheet new_folder/chicken_sheet.xlsx 1SeFXkr3XdzPSuWauz… <named list>  
#> 
#> [[3]]
#> # A dribble: 1 × 4
#>   name        local_path             id                           drive_resource
#>   <chr>       <chr>                  <drv_id>                     <list>        
#> 1 chicken.csv new_folder/chicken.csv 1VOh6wWbRfuQLxbLg87o58vxJt9… <named list>

Created on 2022-06-16 by the reprex package (v2.0.1)

Thanks to everyone for this great package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature folder 📁 future
Projects
None yet
Development

No branches or pull requests

3 participants