How to list all files, folders, subfolders and sub

2019-02-11 07:34发布

问题:

Any ideas how to query for all the children and the children of the children in a single query?

Update

It seems like a simple question. I doubt if there is a simple solution?

Quering the tree of folders and files can cost a lot of API calls. So, to solve my problem, I use a single query to list all the files and folders of an owner. This query also returns subfiles and subfolders. To find the folder and all of its children (folder, files, subfolders and subfiles) in the list, I had to create a tree like index.

Conclusion

A single query is not enough. You have to list all or narrow the query with an owner. Next You have to index the results to (recursive) find the tree for the folder.

A query option like (ls -R in Unix) would be nice.

回答1:

I think you have the right idea in your "update". Treat Drive as flat, make calls to list everything, and generate your own tree from that.



回答2:

I'm trying to do the same in PHP. My solution is:

  1. Retrieve the complete list of files and folders from the drive
  2. Make a double iteration (nested) on the retrieved json:
    • the first over the elements in "items" array,
    • the second (recursive) over the parents id of each element,

rejecting all the elements that not contain the id of my specific folder in its parents id list.
Don't worry, it's just one Google APIs call. The rest of the job is local.