Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pydrive get only folders from list

I use library pydrive for google drive. Now I need get all folders (root, parent, child) name in google drive.
I have found this:

self.drive.ListFile().GetList()

but it returns all the files. Can I get only all folders in google drive?

like image 373
r1299597 Avatar asked Jan 15 '18 08:01

r1299597


1 Answers

How about this modification? It retrieves the files with mimeType of application/vnd.google-apps.folder using query.

  • The mimeType of application/vnd.google-apps.folder means folders.
  • trashed=false means that files are retrieved from outside of the trashbox.
  • In this case, title means folder name.

Modified script :

f = self.drive.ListFile({"q": "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList()
for folder in f:
    print(folder['title'])

References :

  • About q

If I misunderstand your question, I'm sorry.

like image 168
Tanaike Avatar answered Oct 15 '22 20:10

Tanaike