0

How do I do a simple recursive listing to build a directory structure?

I am using gdata python client library. Looking at the client.py and data.py, there is no straight forward way to list and build a directory structure.

What I am doing is: (Assuming self.client has been authenticated)

  1. self.client.GetAllResources (include showfolders=true)
  2. For every resource check resource.in_collections()

Is there a better way than above?

thanks

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
Srini K
  • 13
  • 1
  • 3
  • The way I am currently doing this in my gdrive-cli project is by storing the file metadata in a local sqlite database. http://github.com/tom-dignan/gdrive-cli – Thomas Dignan May 01 '12 at 19:05
  • Thanks. I looked at your code but not sure where you are handling collections/folders. Do you support them in gdrive-cli? – Srini K May 01 '12 at 21:22
  • collections aren't implemented yet, only listing the files in a flat way is – Thomas Dignan May 02 '12 at 10:21

1 Answers1

2

An alternative way is to first scan the hierarchy for folders only, and for each folder, list all the resources. You can pass any URI into the GetAllResources method, and in this case it would be:

  1. For folders only in the root:

    https://docs.google.com/feeds/default/private/full/folder%3Aroot/contents/-/folder

  2. For contents of the folder with ID 123456:

    https://docs.google.com/feeds/default/private/full/folder%3A123456/contents/

By default folders themselves are not listed in the contents feed, so you can combine these two to get the entire hierarchy.

I think I prefer your method above to get a flat list and generate the folder hierarchy, this is just offering an alternative.

Ali Afshar
  • 40,967
  • 12
  • 95
  • 109