Want to know more about Dash? Check out how Amy uses Dropbox and Dash to make her day easier here! 

Forum Discussion

pojler's avatar
pojler
New member | Level 2
5 years ago
Solved

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

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 Reply

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,018 PostsLatest Activity: 2 years ago
402 Following

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!