How to find folder in google drive
Solution 1
Edit as per Mike's comment:
name='foldername' is no longer correct in 2022
The new syntax should be:
mimeType='application/vnd.google-apps.folder' and title = 'foldername'
Original answer:
Query should be as follows:
mimeType='application/vnd.google-apps.folder' and name='foldername'
In 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()
Note: name='foldername'
not title='foldername'
Solution 2
You can add the q
query parameter to your request URL and use the Drive query language to restrict your search:
https://developers.google.com/drive/search-parameters
To search for folders only and restrict the search by title, your query should look like:
mimeType = 'application/vnd.google-apps.folder' and title = 'My_Folder_name'
Comments
-
quantm almost 2 years
I have implement the function upload file to google drive. I have done it following the guide in quick start.
Now i'm doing the function upload file to specific folder *(Ex: upload file to "My_Folder_name")*. I found the sample in API Reference. The trouble is how can i get the parentId (folder id) if i only know the name of folder.
I could not find any function to search folder by name...
Is the only one way to get folder by get all the files, then check MimeType is equals with "application/vnd.google-apps.folder" and compare it with folder name.
if("application/vnd.google-apps.folder".equals(body.getMimeType()) && "My_Folder_name".equals(body.getTitle()) ){ .... }
Thanks in advance.
-
Vnge about 11 yearshow do you do this programatically?
-
Claudio Cherubino about 11 yearsin Java, use the setQ method
-
Vnge about 11 yearswould it be possible to get a code example or documentation with code examples?
-
IvanRF over 8 yearsadd
and trashed = false
if you only want untrashed folders -
Admin about 8 yearsIf I have same name folder in google drive then it will give two folder ?
-
Mujeeb over 2 yearsIn my case, even after having the correct code the folder wasn't being listed. Figured out since I was using a service account to upload files (to the folder on Google Drive), I needed to share that folder with the service account too.
-
Gaurav about 2 yearsCan we crawl one or more folders inside the parent folder? In other words, Can we download the files from multiple parent folders? For example, 2022 Folder > January > 01142022.csv 2022 Folder > February > 02142022.csv I have 2022 (year) as a grandparent and January(month) as a parent folder and 02142022.csv as child file. how to download the files every month which arrives every month. I can only give the folder id of 2022 hard-coded and month-based folder id has to be taken up automatically. Please guide. I want to download all CSV files with their parent and grand parents
-
ChickenFeet about 2 yearsSorry @Gaurav, comment section is not for asking further questions about a very specific problem you are facing. Of course what you're saying is possible, you just need to know how to code it. Do some reading and write your script step by step, take baby steps and solve each little problem separately. We're not here to do your work for you
-
Mike Johnson Jr about 2 yearsname='foldername' is no longer correct in 2022
-
ChickenFeet about 2 years@MikeJohnsonJr care to share the correct syntax?
-
Mike Johnson Jr about 2 yearstitle = 'foldername'