I get files from google drive, like that. The result of Folders. ok,
I have List result, so I want to find if result(i) have children with application/vnd.google-apps.folder mime type or not.
in the other words, method which checks: if current folder contains children folder returns true. owherwise returns false;
I use it in google App engine.
how can I do that?
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);
}
I do not want to create additional requests (new children request to each node) to see if it have children or not. something like that:
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);
}
I want to optimize my code.