我从谷歌驱动器获取文件,就像那样。文件夹的结果。好的,
我有List result,所以我想知道 result(i) 是否有 application/vnd.google-apps.folder mime 类型的孩子。
换句话说,检查:如果当前文件夹包含子文件夹的方法返回true。否则返回 false;
我在谷歌应用引擎中使用它。
我怎样才能做到这一点?
public void getAllFiles(String id, Drive service) throws IOException{
String query="'"+id + "'"+ " in parents and trashed=false and mimeType=application/vnd.google-apps.folder'";
FileList files = service.files().list().setQ(query).execute();
List<File> result = new ArrayList<File>();
Files.List request = service.files().list();
do {
result.addAll(files.getItems());
request.setPageToken(files.getNextPageToken());
} while (request.getPageToken() != null && request.getPageToken().length() > 0);
}
我不想创建额外的请求(对每个节点的新子请求) 来查看它是否有子节点。类似的东西:
for (File file : result) {
query = "'" + file.getId() + "'" + " in parents and trashed=false and mimeType='application/vnd.google-apps.folder'";
FileList fileChild = service.files().list().setQ(query).execute();
List<File> res = new ArrayList<File>();
Files.List req = service.files().list();
do {
res.addAll(fileChild.getItems());
req.setPageToken(fileChild.getNextPageToken());
} while (req.getPageToken() != null && req.getPageToken().length() > 0);
RemoteFolder remFolder = new RemoteFolder();
remFolder.setFile(file);
if(res.size()>0){
remFolder.setChildrenable(true);
log.info("folder named "+file.getTitle() + " have children folders count: "+ res.size());
}
folderList.add(remFolder);
}
我想优化我的代码。