简体   繁体   English

如何列出Google云端硬盘文件夹的所有文件,文件夹,子文件夹和子文件

[英]How to list all files, folders, subfolders and subfiles of a Google drive folder

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. 查询文件夹和文件树可能会花费大量API调用。 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. 像(Linux中的ls -R)这样的查询选项会很好。

I'm trying to do the same in PHP. 我想在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: 在检索到的json上进行双重迭代(嵌套):
    • the first over the elements in "items" array, 第一个超过“items”数组中的元素,
    • the second (recursive) over the parents id of each element, 第二个(递归)每个元素的父ID,

rejecting all the elements that not contain the id of my specific folder in its parents id list. 在父父ID列表中拒绝所有不包含我特定文件夹id的元素。
Don't worry, it's just one Google APIs call. 别担心,这只是一个Google API调用。 The rest of the job is local. 剩下的工作是本地的。

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. 将Drive视为平面,调用列出所有内容,并从中生成自己的树。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 PyDrive (Python) 访问文件夹、子文件夹和子文件 - Accessing folders, subfolders and subfiles using PyDrive (Python) 使用 PyDrive 列出共享的 Google Team Drive 文件夹中的所有文件 - List all files in folder in shared Google Team Drive using PyDrive Google Drive Api客户端:如何获取文件夹中的文件列表 - Google Drive Api Client: How to get the list of files in a folder Google Drive API v3:service.files().list 不返回所有文件夹 - Google Drive API v3: service.files().list not returning all folders 使用python的谷歌驱动器文件夹中的文件列表 - List of files in a google drive folder with python 如何计算所有文件夹和子文件夹中具有特定扩展名的文件数 - How to count the number of files with a specific extension in all folders and subfolders Python:如何在ALL文件,文件夹和子文件夹的名称中用下划线替换空格? - Python: How to replace whitespaces by underscore in the name of ALL files, folders and subfolders? 如何将包含多个文件夹的文件夹从谷歌驱动器上传到谷歌 colab - How to upload folder with multiple folders from google drive to google colab 使用Python计算所有文件夹/子文件夹中的所有文件 - Count all files in all folders/subfolders with Python 如何列出特定谷歌驱动器目录 Python 中的所有文件 - How to list all the files in a specific google drive directory Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM