Carlos Santini
Carlos Santini

Reputation: 77

How can we list all files from a specific folder on Google Drive

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

Upvotes: 3

Views: 11210

Answers (4)

Datusa
Datusa

Reputation: 101

Using googleApis V3 you can do it. This is sample code:

string FolderId = "1lh-YnjfDFMuPVisoM-5p8rPeKkihtw9";
        // Define parameters of request.
        FilesResource.ListRequest listRequest = DriveService.Files.List();
        listRequest.PageSize = 10;
        listRequest.Q = "'" + FolderId + "' in parents and trashed=false";
        listRequest.Fields = "nextPageToken, files(*)";

        // List files.
        IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute()
            .Files;

Hope this help.

Upvotes: 1

Anurag Srivastava
Anurag Srivastava

Reputation: 473

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.

Upvotes: 3

Pir Fahim Shah
Pir Fahim Shah

Reputation: 10633

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());
  }

Upvotes: -2

JunYoung Gwak
JunYoung Gwak

Reputation: 2987

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.

Upvotes: 5

Related Questions