使用带有Java的Google Drive API,如何仅列出驱动器部分/文件夹中的文件 [英] Using Google Drive API with Java, how to list only files in the Drive Section/Folder

查看:150
本文介绍了使用带有Java的Google Drive API,如何仅列出驱动器部分/文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取Google云端硬盘特定部分中的所有文件。



这些是我正在查找的文件:





您可以看到一个名为 Projet 3 和一个名为 Processus TP2 questions 的文件。在文件夹中,我只有一个文件。



但是,当我尝试列出所有文件时,我收到了数千个文件。如果我使用Google云端硬盘顶部的搜索栏搜索它们,它会找到它们,但我不知道它们在哪里(可能是Gmail的附件?)。

是我的搜索查询:

  FileList result = service.files()。list()
.setQ(mimeType !='application / vnd.google-apps.folder'
和trashed = false)
.setSpaces(drive)
.setFields(nextPageToken,files(id,name,父母))
.setPageToken(pageToken)
.execute();

如何只列出我可以在Web UI上的云端硬盘部分/文件夹中看到的文件?



非常感谢。 使用父母属性在你的查询中,像这样:

$ p $ FileList result = service.files().list()
.setQ ('drive')
.setFields(nextPageToken,files(())'父'和'mimeType!'='application / vnd.google-apps.folder'和trashed = false id,name,parents))
.setPageToken(pageToken)
.execute();

如果您想列出特定文件夹的内容而不是root - 请使用该文件夹的ID,而不是查询中有'root'。


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:

You can see a folder named Projet 3 and a file named Processus TP2 questions. In the folder I only have one file.

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?).

This is my search query:

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();

How can I list only the files I can see in my Drive Section/Folder on the web UI?

Thank you very much.

解决方案

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();

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,如何仅列出驱动器部分/文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆