Finding a path to a file with its identifier

I get a FileList with:

String q = "title contains '"+query+"' and trashed = false"; FileList list = drive.files().list().setQ(q).execute(); 

I want to find the path to each corresponding file in a FileList.

I understand that the same file can be displayed in several folders.

From what I found, the only way to create a file path is to re-call:

  drive.files().get(id).execute() 

and then select the identifier from this list of file files, raise the tree to reach the root.

While navigating the tree, I could just pick the first parent or make a “BFS” until I find the root.

Is this really the only way to find the path to the file, or am I missing the API part?

If this is the only way, can folders with multiple parents also make loops possible?

(/ a / b / c => / a / b / c / b / c / b / c ... if b has parents a and c)?

+7
source share
1 answer

Since folders (which are just a special disk file with a specific MIME type) can have multiple parents, I would recommend the BFS approach and make sure you handle the loops.

In stop mode, you can save the root folder identifier, which you can get from the about.rootFolderId attribute.

+4
source

All Articles