cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Searching for all files with certain extension in Java API and some issues with search queries

Searching for all files with certain extension in Java API and some issues with search queries

pojler
New member | Level 2

Hello!

I'm building a small function in which i want to get metadata from for example all of PDF's and DOC files. So I am using a SearchV2Builder withFileExtension option. But i don't know hot write a query for any string. I tried with regexes, wildcards characters and nothing works.

```

private final String extensions[] = {"pdf","docx","doc","odt","jpg"};

public void
findFile(String query){
try{

SearchV2Builder searchBuilder = client.files().searchV2Builder(query);

List<String> fileExtensions = Arrays.asList(extensions);
SearchOptions searchOptions = SearchOptions.newBuilder().withFileExtensions(fileExtensions).build();

SearchV2Result searchResult = searchBuilder.withOptions(searchOptions).start();
List<SearchMatchV2> searchMatches = searchResult.getMatches();

System.out.println(searchMatches.size());
for (SearchMatchV2 s: searchMatches){
System.out.println(s.getMetadata().getMetadataValue().getPathDisplay());
}

}
catch(DbxException e){
e.printStackTrace();
}

}

```

So my question is how to write that query? Maybe there is different solution for that. Thanks in advance!

 
 
 
 
 
1 Accepted Solution

Accepted Solutions

Re: Searching for all files with certain extension in Java API and some issues with search queries

Greg-DB
Dropboxer

[Cross-linking for reference: https://stackoverflow.com/questions/66518862/dropbox-sdk-java-write-search-query-to-get-all-files ]

 

The Dropbox API doesn't offer the ability to do a wildcard search like this, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.

 

While not ideal, as a workaround, you could list the full contents using listFolder/listFolderBuilder/listFolderContinue and filter based on the file extension.

 

View solution in original post

1 Reply 1

Re: Searching for all files with certain extension in Java API and some issues with search queries

Greg-DB
Dropboxer

[Cross-linking for reference: https://stackoverflow.com/questions/66518862/dropbox-sdk-java-write-search-query-to-get-all-files ]

 

The Dropbox API doesn't offer the ability to do a wildcard search like this, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though.

 

While not ideal, as a workaround, you could list the full contents using listFolder/listFolderBuilder/listFolderContinue and filter based on the file extension.

 

View solution in original post

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?