How to find a folder in Google Drive

I am implementing a function download file on a Google drive. I did this after the guide in quick start .

Now I am loading the function into a specific folder * (Example: loading a file in "My_Folder_name") *. I found a sample in the API Reference . The problem is how can I get parentId (folder id) if I only know the folder name.

I could not find any function to search for a folder by name ...

This is the only way to get the folder by getting all the files, and then check that MimeType is equal to "application / vnd.google-apps.folder" and compare it with the name of the folder.

if("application/vnd.google-apps.folder".equals(body.getMimeType()) && "My_Folder_name".equals(body.getTitle()) ){
            ....        
}

Thanks in advance.

+5
source share
3

q URL- , :

https://developers.google.com/drive/search-parameters

, :

mimeType = 'application/vnd.google-apps.folder' and title = 'My_Folder_name'
+10

:

mimeType='application/vnd.google-apps.folder' and name='foldername'

Python:

service.files().list(q="mimeType='application/vnd.google-apps.folder' and name='foldername'",
                                         spaces='drive',
                                         fields='nextPageToken, files(id, name)',
                                         pageToken=page_token).execute()

: name='foldername' not title='foldername'

+1

You need to do two things:

Use files.list (which gives full file resources) ( https://developers.google.com/drive/v2/reference/files/list ). Modify your request to add the parent id that you want to execute.

mimeType = 'application / vnd.google-apps.folder' and 'folderId' in parents

-1
source

All Articles