How can we list all files from a specific folder o

2019-02-24 22:54发布

We noticed that Google Drive API Javascript allows you to list all files from an specific folder, however it brings just basic details from the file. If we want to know more such as the file name we need to query the API again for each single file. Is there a way that we can list more details of the file such as the file name from a single folder list query?

Thanks

3条回答
Fickle 薄情
2楼-- · 2019-02-24 23:16

I guess you used Children.list(). It only lists id of children which is not the function you want. You should rather use Files.list() with parameter q="'{{FOLDER_ID}}' in parents" and it will list all the files and its details of children of specific folder you want.

查看更多
爷的心禁止访问
3楼-- · 2019-02-24 23:23

I did much googled for this question but the answer is right here. You have to use following code snippet as i had used:

Files.List request = mService.files().list().setQ("'Your Folder ID Here' in parents");
FileList files = request.execute();
if (files != null) {
  for (File file : files.getItems()) {
    // Meta data
    Log.i("", "Title: " + file.getTitle());
    Log.i("", "Description: " + file.getDescription());
    Log.i("", "MIME type: " + file.getMimeType());
  }
}

I am sure it will work for you.

查看更多
迷人小祖宗
4楼-- · 2019-02-24 23:30

Don't worry about this problem, its easy. If you want to get all files and folder from specific FOLDER, then just copy and paste this code in your project and it will retrieve all the files and folder from the specific Folder. Note: You should have your own Folder ID

 List<File> result = new ArrayList<File>();
    Files.List request = null;

    try {
          request = mService.files().list();//plz replace your FOLDER ID in below linez
          FileList files = request.setQ("'"+MyFoler_Id+"'in parents and trashed=false").execute();
          result.addAll(files.getItems());          
          request.setPageToken(files.getNextPageToken());
        } 
      catch (IOException e)
      {
        System.out.println("An error occurred: " + e);
        request.setPageToken(null);
      }

//Print Out the Files and Folder Title which we have retrieved.

  for(File f:result)
  {
      System.out.println("My recvd data "+f.getTitle());
  }
查看更多
登录 后发表回答