Finding a path to a File given it's ID

Viewed 2747

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 a path to each matching file in the FileList.

I understand that the same File can appear in multiple Folders.

From what I've found, the only way to create a path for a File is to repeatedly call:

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

and then choose an ID from that File's parents list, walking up the tree until the root is reached.

While navigating the tree, I could just choose the first parent, or do a "BFS" until I find the root.

Is this really the only way to find a path to a File, or have I missed some part of the API?

If this is the only way, can Folders have multiple parents, too, making cycles possible?

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

1 Answers
Related