cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We recently received a question asking for advice on how to set up a Dropbox account for an elderly family member. This prompted us to think about the different ways we can make Dropbox more accessible in general, learn about it and add your tips right over 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: 
1
Ask
2
Comments

[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

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

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

Greg-DB
Dropboxer
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

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

Greg-DB
Dropboxer
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!

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

Victor V.3
Explorer | Level 3
Hi Greg,

This solves my problem indeed.
Thanks.

-victor
Who's talking

Top contributors to this post

  • User avatar
    Victor V.3 Explorer | Level 3
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?