Query for list of files and folders in root directory

后端 未结 3 1508
我寻月下人不归
我寻月下人不归 2021-02-05 14:46

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?

3条回答
  •  悲哀的现实
    2021-02-05 15:06

    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 fileNames = new ArrayList();
        for (File file : files.getFiles()) {
            fileNames.add(file.getName());
        }
        children = fileNames.toArray(new String[0]);
        return children;
    }
    

提交回复
热议问题