Kuffs
Kuffs

Reputation: 35661

Enumerating folders and files using Google Drive SDK V2

I am a little confused by the v2 Google Drive SDK.

There seems to be 2 methods to retrieve information about files and folders.

files.list and children.list

Using files.list I do not seem to be able to narrow my search to files in a specific folder but using children.list only returns very basic file information such as ID. There are no filenames.

It looks like I have to retrieve a list of children and then perform a request for each child to find out its filename which seems very inefficient.

What is the normal\correct way to enumerate folders and their contents using Google Drive?

Upvotes: 9

Views: 2611

Answers (4)

Navi
Navi

Reputation: 449

If you want to get all the folders in your drive use :

FileList folders=service.files().list().setQ("mimeType='application/vnd.google-apps.folder'").execute();
for(File fl: folders.getItems()){
     Log.v(TAG+" fOLDER name:",fl.getTitle());
}  

Upvotes: 1

Steve Bazyl
Steve Bazyl

Reputation: 11672

Alternative approach is to use files.list with a query expression to limit by parent.

q='id-of-parent' in parents 

This will give you the same results as the child collection, but with the full metadata for each item.

Upvotes: 2

Ali Afshar
Ali Afshar

Reputation: 41653

Update --

This can now be achieved with files.list. You can pass the q parameter with a query testing the parents of a file or folder.

q='MYFOLDERID' in parents

More search parameters and options and examples here: https://developers.google.com/drive/search-parameters

Original answer --

Yes, this is correct. We are looking to improve this feature, but unfortunately you are stuck with this for now - sorry.

If you are enumarating all the files and folders, a better solution might be to get a flat list, and use the parents array in a file to generate the hierarchy.

Upvotes: 2

Takahiro
Takahiro

Reputation: 1262

+1 returning metadata (at least filename) for children.list

Upvotes: 2

Related Questions