Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the right way to find files by "full path" in Google Drive API v2

Tags:

dear all

I'm trying to find a list of documents by "full path". And after reading the API reference, it seems to be a complex task. Assume my path is something like /path0/path1/path2/...

  1. List children of root folder and find all children with name equals "path0" and put them to a list "result0"
  2. Find all children of items in "result0" with name equals "path1" and put them to a list "result1"
  3. Find all children of items in "result1" with name equals "path2" and ...

Above approach seems very low efficient cause it needs multiple interactions between my application and Drive. I understand Google Drive allows multiple files share the same file name even in the same folder. It will be handy if I can do something like:

listDocByFullPath("path0/path1/path2") 

Is this possible with current version of Google Drive SDK? If it's not there yet, I was wondering if there is a simpler way than what I listed here.

BTW, as my application is purely a back-end service, it's not possible to use file picker provided by Google.

Cheers.

like image 509
James Gan Avatar asked Jun 23 '13 23:06

James Gan


People also ask

How do I find full file path?

Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).

How do I find everything in Google Drive?

To open the Google Drive advanced search, click on the drop-down arrow at the end of the Google Drive search box, and you will find that you can search by file type, visibility, owner and much more!

Is there an API for Google Drive?

The Google Drive API allows you to create apps that leverage Google Drive cloud storage. You can develop applications that integrate with Drive, and create robust functionality in your application using the Drive API.


2 Answers

Unlike conventional file systems, a file could be under multiple folders on Drive. Folders are pretty much similar what labels are. Therefore, conventional paths dont always work within our abstraction. I'd suggest you to follow the logic below:

  1. List files with q = 'root' in parents and title = 'path0' and mimeType = 'application/vnd.google-apps.folder' and pick the first result.
  2. If there is a matching result, get the folder's id and perform another listing with '<id of path0>' in parents and title = 'path1' and mimeType='application/vnd.google-apps.folder' and pick the first result.
  3. Keep going until you reach to your target folder.
like image 103
Burcu Dogan Avatar answered Sep 29 '22 19:09

Burcu Dogan


The biggest problem is that a path does not uniquely identify the file or folder! For example, in the web UI, you can make 2 folders with the same name as children of the same folder. i.e. you can make a tree that looks like: root |-somefolder |-somefolder

like image 42
Rehan Avatar answered Sep 29 '22 18:09

Rehan