問題描述
我正在嘗試獲取 Google Drive 特定部分(驅動器部分)中的所有文件.
I am trying to get all files that are in a specific section of Google Drive (The Drive Section).
這些是我正在尋找的文件:
Those are the files I am looking for:
您可以看到一個名為 Projet 3
的文件夾和一個名為 Processus TP2 questions
的文件.在文件夾中我只有一個文件.
You can see a folder named Projet 3
and a file named Processus TP2 questions
. In the folder I only have one file.
但是當我嘗試列出所有文件時,我得到了數千個文件.如果我使用 Google Drive 頂部的搜索欄搜索它們,它會找到它們,但我不知道它們在哪里(可能是 Gmail 附件?).
But when I try to list all the files, I get thousands of files. If I search for them using the search bar on top of Google Drive, it finds them, but I have no idea where they are (maybe Gmail attachement?).
這是我的搜索查詢:
FileList result = service.files().list()?
.setQ("mimeType != 'application/vnd.google-apps.folder'
and trashed = false")?
.setSpaces("drive")
.setFields("nextPageToken, files(id, name, parents)")
.setPageToken(pageToken)?
.execute();
如何僅列出我可以在網絡 UI 上的驅動器部分/文件夾中看到的文件?
How can I list only the files I can see in my Drive Section/Folder on the web UI?
非常感謝.
推薦答案
在查詢中使用parents"屬性,如下所示:
Use "parents" property in your query, like this:
FileList result = service.files().list()?
.setQ("'root' in parents and mimeType != 'application/vnd.google-apps.folder' and trashed = false")?
.setSpaces("drive")
.setFields("nextPageToken, files(id, name, parents)")
.setPageToken(pageToken)?
.execute();
如果您想列出特定文件夾的內容而不是根目錄 - 在查詢中使用該文件夾的 ID 而不是根目錄".
If you want to list the contents of a specific folder rather than root - use that folder's id instead of 'root' in the query.
這篇關于使用帶有 Java 的 Google Drive API,如何僅列出 Drive Section/Folder 中的文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!