Google Drive API:列出没有父级的文件 [英] Google Drive API: list files with no parent

查看:121
本文介绍了Google Drive API:列出没有父级的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我管理的Google域中的文件已进入糟糕状态;有数千个文件驻留在根目录中。我想识别这些文件,并将它们移动到My Drive下面的文件夹中。



当我使用API​​列出其中一个孤立文件的父项时,结果是一个空数组。要确定一个文件是否是孤立的,我可以迭代我的域中的所有文件,并请求每个父文件的列表。如果列表为空,我知道该文件是孤立的。



但这是非常慢的。

是否有使用Drive API来搜索没有父母的文件?



q参数的父母字段似乎没有用处,因为只能指定父母列表包含某个ID。 p>

更新:

我试图找到一种快速查找项目的方法真正处于文档层次结构的根源。也就是说,他们是My Drive的兄弟,而不是My Drive的孩子。

p>

 列表< File> result = new ArrayList< File>(); 
Files.List request = drive.files()。list();
request.setQ(父母中的root+);

FileList files = null;
files = request.execute(); (com.google.api.services.drive.model.File元素:files.getItems()){
System.out.println(element.getTitle());



'root'是父文件夹,如果文件或文件夹在根


The files in Google domain that I administer have gotten into a bad state; there are thousands of files residing in the root directory. I want to identify these files and move them to a folder underneath "My Drive".

When I use the API to list the parents for one of these orphaned files, the result is an empty array. To determine if a file is orphaned, I can iterate over all the files in my domain, and request the list of parents for each. If the list is empty, I know that the file is orphaned.

But this is hideously slow.

Is there anyway to use the Drive API to search for files that have no parents?

The "parents" field for the q parameter doesn't seem to be useful for this, as it's only possible to specify that the parents list contains some ID.

Update:

I'm trying to find a quick way to locate items that are truly at the root of the document hierarchy. That is, they are siblings of "My Drive", not children of "My Drive".

解决方案

In Java:

List<File> result = new ArrayList<File>();
Files.List request = drive.files().list();
request.setQ("'root'" + " in parents");

FileList files = null;
files = request.execute();

for (com.google.api.services.drive.model.File element : files.getItems()) {
    System.out.println(element.getTitle());
}

'root' is the parent folder, if the file or folder is in the root

这篇关于Google Drive API:列出没有父级的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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