How to search for a file inside a specific folder in google API v3

How I use v3 google api so instead of using parent and child list I need to use fileList, so now I want to search for file list inside a specific folder. So can someone suggest me what to do?

Here's the code I'm using to find the file:

private String searchFile(String mimeType,String fileName) throws IOException{
    Drive driveService = getDriveService();
    String fileId = null;
    String pageToken = null;
    do {
        FileList result = driveService.files().list()
                .setQ(mimeType)
                .setSpaces("drive")
                .setFields("nextPageToken, files(id, name)")
                .setPageToken(pageToken)
                .execute();
        for(File f: result.getFiles()) {
            System.out.printf("Found file: %s (%s)\n",
                    f.getName(), f.getId());
            if(f.getName().equals(fileName)){
                //fileFlag++;
                fileId = f.getId();
            }
        }
        pageToken = result.getNextPageToken();
    } while (pageToken != null);

    return fileId;
}

      

But in this method, it gives me all the files that are generated that I don't want. I want to create a FileList that will give a file inside a specific folder.

+3


source to share


2 answers


Searching for files by folder name is not yet supported. It was requested on this google forum but nothing so far. However, try looking for other alternative search filters available in Find Files .

Be creative. For example, make sure the files in a particular folder contain a unique keyword that you can query with



 fullText contains 'my_unique_keyword'

      

0


source


you can use this method to search files from google drive.



    Files.List request = this.driveService.files().list();
    noOfRecords = 100;
    request.setPageSize(noOfRecords);
    request.setPageToken(nextPageToken);
    String searchQuery = "(name contains 'Hello')";
    if (StringUtils.isNotBlank(searchQuery)) {
        request.setQ(searchQuery);
    }
    request.execute();

      

0


source







All Articles