cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

Re: [java sdk v2] check if entry of a listResult is a file

[java sdk v2] check if entry of a listResult is a file

Victor V.3
Explorer | Level 3
Go to solution

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

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution
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/c...

Hope this helps!

View solution in original post

2 Replies 2

Greg-DB
Dropbox Staff
Go to solution
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/c...

Hope this helps!

Victor V.3
Explorer | Level 3
Go to solution
Hi Greg,

This solves my problem indeed.
Thanks.

-victor
Need more support?