We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Victor V.3
10 years agoExplorer | Level 3
[java sdk v2] check if entry of a listResult is a file
Hi,
With Java Sdk V1 I was able to do build a list of my own type of objects based only on the files I was finding in a dropbox path:
List<DbxEntry> dbxEntries = dbxClient.searchFileAndFolderNames(path, query);
for (DbxEntry child : dbxEntries)
{
if (child.isFile())
{
StorageFileImpl i = new StorageFileImpl();
i.setName(child.name);
i.setPath(child.path);
i.setCreationDate(child.asFile().lastModified);
result.add(i);
}
}
I'm trying to do the same thing with Sdk V2.
I've considered 2 options:
1. using files().searchBuilder - but the query param is not helping me at all. I'd like to be able to ignore it or pass empty string as a value for it, but as far as I've tried, that doesn't work..
dbxClient.files().searchBuilder(path, query).withMode(SearchMode.FILENAME).start();
2. using files().listFolderBuilder - but I get entries for folders as well, and I can't exclude them although I saw while debugging that each entry has a file / folder .tag
dbxClient.files().listFolderBuilder(path).withRecursive(true).start();
My code would be the following:
listResult.getEntries().stream()
.forEach(entry -> {
// check it is a file
// ???
StorageFileImpl i = new StorageFileImpl();
i.setName(entry.getName());
i.setPath(entry.getPathDisplay());
// i.setCreationDate(entry.notYetAvailable());
result.add(i);
});
How can I keep only the file .tag type entries ?
Or what other options do I have ?
thanks,
-victor
- Hi Victor, you can use instanceof to determine if a particular entry is a file or folder, as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/FilesAdapter.java#L82
Hope this helps!
2 Replies
- Greg-DB10 years ago
Dropbox Community Moderator
Hi Victor, you can use instanceof to determine if a particular entry is a file or folder, as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/FilesAdapter.java#L82
Hope this helps! - Victor V.310 years agoExplorer | Level 3Hi Greg,
This solves my problem indeed.
Thanks.
-victor
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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, Facebook or Instagram.
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!