3

I am using the Java SDK (version 3.1.7) and cannot seem to find a way to find a file by path; the only way seems to be to walk through the root, check that the name exists, that it is a directory, pick its id, goto 1.

Also, there doesn't seem to be a search option for that either.

So, is it possible at all?

fge
  • 119,121
  • 33
  • 254
  • 329

1 Answers1

2

You're correct - the only way to find a file by path is to recursively walk the user's file tree. However, we do have a new beta version of our SDK that makes it easier to iterate over folders. It also includes a small example showing how you would go about walking the user's account.

The reason why the SDK doesn't provide this functionality is because searching for files/folders by path can be really inefficient. It would be really easy to inadvertently call getItemByPath("/path/to/my/file") not realizing it will require at least 4 API requests (at least one for each folder). In general, you should try to access items by their ID instead.

Greg
  • 3,731
  • 1
  • 29
  • 25
  • Hmmm, interesting. In fact it is for [this project](https://github.com/fge/java7-fs-dropbox). Since this project is beta, I might as well give a shot at that new SDK! – fge Dec 10 '14 at 09:48
  • Also, why isn't this SDK advertised on developer.box.com? – fge Dec 10 '14 at 09:50
  • We just released the beta yesterday, so we haven't gotten a chance to add it to our developer site - but it will be soon! – Greg Dec 10 '14 at 21:27
  • By beta, do you mean 0.5.0? Anyway, this is now what I am using (on a separate branch), and I see that it requires Java 7; there are a few cases out there where you could make use of Throwable's .addSuppressed() ;) – fge Dec 10 '14 at 22:40
  • Yeah, the beta is just whatever the latest pre-release version is (anything that's 0.*.*) Feel free to file issues on GitHub for any potential improvements/issues you come across. I'll be happy to take a look at them. – Greg Dec 11 '14 at 00:48