Identifying list of xlsx files from the cloud (google drive)

100 Views Asked by At

I am trying to create a loop where I can perform the same set of functions for a bunch of files. However, the files are stored on a shared folder in google drive (xlsx files) and I can't seem to get the code to "find them". I am working on a Mac (if that makes a difference).

Here is an example of what I have tried:

library("googledrive")
library("readxl")
library("curl")
library("googlesheets")
library("xlsx") # and a few more which I have tried!

> setwd("/Users/xxx/Documents/R") #working on a Mac
> WS.URL <- "https://drive.google.com/drive/u/0/folders/xxx" # this is the shared 
drive folder containing numerous xlsx files


##a - the main one I am trying to do ###
> list.files(path = "WS.URL")
character(0) ## there are about 10 files in this folder which aren't showing up. I can't create a loop if I can't retrieve the files.

#b
> nfiles <-length(WS)
> nfiles
[1] 1 # should be about 10


#c
dest <- ("/Users/xxx/Documents/R")
try(download.file("WS.URL", dest))

I have no idea if I am missing something really obvious, still getting to grips with R. Surely this should be straightforward?

HELP!

1

There are 1 best solutions below

0
Linda Lawton - DaImTo On

I cant help much with R but there is a parameter on file.list method called q its used for searching

GET https://www.googleapis.com/drive/v3/files?q=sharedWithMe

by return sending q=sharedWithMe it should return all the files that are shared with you. Testing the q method is easer using the Google APIs exploerer you might want to test it here

Note as far as i know https://drive.google.com/drive/u/0/folders/xxx is not the proper end point for the google drive api which may be causing some of your issues.