cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more 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: Check if a given path is file or folder

Check if a given path is file or folder

Adrian112
New member | Level 2

Hello

I am trying to use your API and to check if a path is a file or a folder. For folders works ok but when I find in my path a file the request crashes with {".tag":"path","path":"not_folder"} (which is normally ).

Here is my code:

String currentUrl = url != null? url :"";
		
		ListFolderResult result = UploadFileToDropbox.createDropBoxConnection().files().listFolder(currentUrl);
		if(result.getEntries().size() >0) {
			for (Metadata metadata: result.getEntries()) {
				if(metadata instanceof FileMetadata)
					System.out.println("file");
			}
			
result.getEntries());
		}

How can I check before this line:

		ListFolderResult result = UploadFileToDropbox.createDropBoxConnection().files().listFolder(currentUrl);

If the current URL is a file in order to prevent this request to fail.

Thank you.

1 Reply 1

Greg-DB
Dropbox Staff

You can catch that not_folder error directly from the listFolder call to detect and handle that. If you do wish to make another call to check it first though, you can do so by calling getMetadata and checking the subtype of the returned Metadata.

Need more support?