更新时间:2023-02-14 13:08:54
如果我对您的理解正确,则希望:
If I understand you correctly, you want to:
当前无法通过单个调用在子文件夹中检索文件.这是因为文件资源(而文件夹"是 File
)不具有有关此父文件夹中包含哪些文件的信息(更不用说包含在子文件夹"中的文件了),并且仅具有有关此文件夹的直接父项的信息,而没有可以这么说.祖父母等等.
It is currently not possible to retrieve files in sub-folders with a single call. That's because a File resource (and a "folder" is a File
) does not have information on what files are contained in this parent folder (let alone files contained in "sub-folders") and it only has information on the immediate parents of this folder, and not grandparents and so on, so to speak.
为了检索所有后裔",某个文件夹,可以使用两种主要方法(主要基于 pinoyyid的答案):
In order to retrieve all "descendants" of a certain folder, two main methods can be used (largely based on this answer by pinoyyid):
所有文件夹
.所有文件夹
.我们将此列表称为直接子代
.直接子代
中的每个元素,请根据其在父代中是否具有相应的直接子代子
来过滤所有文件夹
.这样,您将检索孙代人
的列表.对每个 Grandchildren
元素重复相同的过程,然后为每个 Great-grandchildren
重复此类操作,直到没有文件夹为止.这样,您将检索到主文件夹ID的所有 descendant
文件夹. descendant
文件夹,就必须制作另一个 Files:list
来查找这些文件夹中的任何子文件夹的图像,或者从主文件夹中文件夹.搜索查询可能是这样的:All folders
.All folders
, according to whether they have the main folder ID in parents. Let's call this list Direct children
.Direct children
, filter All folders
according to whether they have the corresponding direct child
in parents. This way, you will retrieve a list of Grandchildren
. Repeat the same process for each Grandchildren
element, then for each Great-grandchildren
and so on, until no folders are left. With this, you will have retrieved all the folders which are descendant
of the main folder ID.descendant
folders, you have to make another Files: list
to find the images which are children of any of those folders, or from the main folder. The search query could be something like this:mimeType contains 'image/' AND ('mainFolderId' in parents OR 'descendant1ID' in parents OR 'descendant2ID' in parents OR...)
(mimeType = 'application/vnd.google-apps.folder' OR mimeType contains 'image/') AND 'folderId' in parents
image/
)还是文件夹(MIME类型: application/vnd.google-apps.folder
).对于每个文件夹,使用上一步中的方法列出其中包含的所有文件.
image/
) or a folder (MIME type: application/vnd.google-apps.folder
). For each folder, list all files contained in it, using the method from previous step.问题跟踪器中有一个开放的功能请求,在查询搜索中包括祖先
,这可以允许在子文件夹中检索子代,并使整个过程更加容易.您可以单击所引用页面左上角的星号,以跟踪此请求并确定优先级:
There is an open feature request in Issue Tracker to include ancestors
in query searches, which could allow the retrieval of children in subfolders, and making this whole process much more easy. You could click the star on the top left of the referenced page in order to keep track of this request and to help prioritize it: