zerozero7
zerozero7

Reputation: 433

Download folder with Google Drive API

I have some data on Google Drive, organized in folders, which I want to propagate on other servers. I have some script for propagating, but I need to download data from google drive. Is there a method for downloading folders via Google Drive API, that is also maintaining whole folder structure?

Upvotes: 6

Views: 14345

Answers (2)

Sanskar Rawat
Sanskar Rawat

Reputation: 1

FileList result = service.files().list().setQ("parents='1NzSAZEwAFARWegk42ANrWQrTopWQTdGB'").setSpaces("drive")
                    .setFields("nextPageToken, files(id, name)")
                    .setPageToken(pageToken)
                    .execute();

The parents parameter is the the fileId of the folder you want to download files from. Doing this you can get all files in that particular folder.

Upvotes: -1

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117271

Folders are also files on Google Drive. The only difference is the Mime type. with folders its mimeType = 'application/vnd.google-apps.folder'.

There is no single method that will allow you to download everything with in a folder. Your going to have to do a file.list searching for the files with the parent Id to the file Id of your parent folder using search parameters (TIP: ''1234567' in parents'). This will return a list of the files contained within your folder. Then download each one.

Update from comment you need to loop though each directory or just do a main list of everything on your drive account and process the data locally.

File 1 (folder)
----> File 2 (folder )
--------> File 3 (actually a file)
---->File Four (actually a file)

'File 1' in parents 

returns everything within the file 1 directory. If the mime type of the item returned is a directory (mimeType = 'application/vnd.google-apps.folder') make a request to get its contences

'File 2' in parents

returns everything within the file 2 directory.

Upvotes: 9

Related Questions