How to download a google drive's contents based on Drive ID, or URL?

OK that is the "file ID" for a folder on Drive. Here's how to download the csv files within it, based just on the URL.

library(googledrive)
library(purrr)

## store the URL you have
folder_url <- "https://drive.google.com/drive/folders/0B7tJg2i5HAo2c0VzVFVhLUdQcnM"

## identify this folder on Drive
## let googledrive know this is a file ID or URL, as opposed to file name
folder <- drive_get(as_id(folder_url))

## identify the csv files in that folder
csv_files <- drive_ls(folder, type = "csv")

## download them
walk(csv_files$id, ~ drive_download(as_id(.x)))
#> File downloaded:
#>   * steamer_pitchers_2018_opp_batter_splits_preseason_final.csv
#> Saved locally as:
#>   * steamer_pitchers_2018_opp_batter_splits_preseason_final.csv
#> File downloaded:
#>   * steamer_pitchers_2018_ros_split_preseason_final.csv
#> Saved locally as:
#>   * steamer_pitchers_2018_ros_split_preseason_final.csv
#> File downloaded:
#>   * steamer_pitchers_2018_ros_preseason_final.csv
#> Saved locally as:
#>   * steamer_pitchers_2018_ros_preseason_final.csv
#> File downloaded:
#>   * steamer_hitters_2018_ros_split_preseason_final.csv
#> Saved locally as:
#>   * steamer_hitters_2018_ros_split_preseason_final.csv
#> File downloaded:
#>   * steamer_hitters_2018_ros_preseason_final.csv
#> Saved locally as:
#>   * steamer_hitters_2018_ros_preseason_final.csv
#> File downloaded:
#>   * steamer_hitters_2018_ros_multi_split_preseason_final.csv
#> Saved locally as:
#>   * steamer_hitters_2018_ros_multi_split_preseason_final.csv

Created on 2018-10-24 by the reprex package (v0.2.1)

5 Likes