6

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?

Kara
  • 6,115
  • 16
  • 50
  • 57
r1299597
  • 609
  • 3
  • 10
  • 20

1 Answers1

10

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 :

If I misunderstand your question, I'm sorry.

Tanaike
  • 181,128
  • 11
  • 97
  • 165