0

with this query:

"name contains '.extension' and 'folderId' in parents"

I get the immediate children with the extension ".extension" in the folder with the folderId.

How can I retrieve all files with this extension in this folder and all its subfolders?

Greg
  • 1,227
  • 5
  • 23
  • 52
  • Unfortunately, in the current stage, there are no methods for directly retrieving all subfolders in a folder using Google APIs. So it is required to prepare a script for achieving it. For this, I think that [this thread](https://stackoverflow.com/q/41741520/7108653) might be useful. – Tanaike Oct 22 '19 at 01:36
  • 1
    As @Tanaike said, there is no direct way of doing this, but there can be a recursive function that achieve this. Please, share your code so we all can get a look at it and help you to fulfill your request. – Jacques-Guzel Heron Oct 22 '19 at 09:10
  • Thank you! I guess I can manage:) – Greg Oct 22 '19 at 09:14

1 Answers1

0

I tried your approach and was able to retrieve all the files with a particular extension from google drive API. I have developed the part of my code using python.

The Query I have used:

q=f"'{folder_id}' in parents and name contains '.extension' and trashed = false"

Also, I have used other field parameters while searching such as

kind,incompleteSearch,files/size,files/id,files/name

In python; the code will look something like the below:

extension_files = self.service.files().list(
                q=f"'{folder_id}' in parents and \
                        name contains '.extension' and trashed = false",
                fields='kind,incompleteSearch,files/size,files/id,files/name'
            ).execute()

Where service you have to set up by the Google drive access token using the build() and credentials.

Hope this will help you in solving your problem.

4b0
  • 21,981
  • 30
  • 95
  • 142