Query for list of files and folders in root directory

Viewed 12039

I would like to get a list of files and folders in the root directory without having to sort through all the files. Is there a query that would do this?

4 Answers

Google drive v3 Reference the documentation helps to create DriveClient object.

Run this below method in the background thread(Android).

Note: Required Scope permission "DriveScopes.DRIVE"

 protected String[] getListChildren(String parentId) throws Exception {
    String[] children = null;
   parentId = parentId == null ? "root" : parentId;
    String fileQuery = "'" + parentId + "' in parents and trashed=false";
    FileList files = driveService.files().list().setQ(fileQuery).execute();
    List<String> fileNames = new ArrayList<String>();
    for (File file : files.getFiles()) {
        fileNames.add(file.getName());
    }
    children = fileNames.toArray(new String[0]);
    return children;
}

The query for a Shared Drive should be "'driveId' in parents.

Using 'root' works for My Drive only.

Related