Search code examples
google-drive-api

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?


Solution

  • 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.