cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Tell us what you want to see on the Community here!
Close

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: 

Check if Folder Exists

Highlighted

Check if Folder Exists

Collaborator | Level 8

Can I do this in my code ?

Are there any better way ?

 

Public Async Function FolderExists(Client As DropboxClient, Optional Path As String = ("/Apps")) As Task(Of Boolean)
        System.Diagnostics.Debug.WriteLine("--- Checking Folder ---")
        Dim list = Await Client.Files.ListFolderAsync(Path)
        ' show folders then files
        For Each item In list.Entries
            If item.IsFolder And item.Name = ("Fav_Name") Then
                MsgBox("Folder Exists. ->" & item.PathLower)
                Return True
                Exit For
            End If
        Next
        Return False
    End Function
1 Accepted Solution

Accepted Solutions
Highlighted

Re: Check if Folder Exists

Dropboxer

Yes, that sounds like a good way to handle the flow of checking for a particular folder and creating it if it doesn't exist.

View solution in original post

3 Replies 3
Highlighted

Re: Check if Folder Exists

Dropboxer

To check if something exists at a particular path, you can instead use GetMetadataAsync. It would return the metadata if the item exists, or will raise an exception with LookupError.NotFound if not.

 

If you only want to check for one particular item, that may be easier/faster than looping through the entire parent folder listing.

 

Note that if you do use ListFolderAsync though, make sure you check the ListFolderResult.HasMore and call back to ListFolderContinueAsync if needed.

Highlighted

Re: Check if Folder Exists

Collaborator | Level 8

@Greg-DB wrote:

To check if something exists at a particular path, you can instead use GetMetadataAsync. It would return the metadata if the item exists, or will raise an exception with LookupError.NotFound if not.

 

If you only want to check for one particular item, that may be easier/faster than looping through the entire parent folder listing.

 

Note that if you do use ListFolderAsync though, make sure you check the ListFolderResult.HasMore and call back to ListFolderContinueAsync if needed.


100% correct.

I my case, I'm using just one FOLDER to enable users to backup thier Database file of a certain version [Thier version] and when updating thier application version later, the app compairs the offline version with the online version of just One File in just One Folder.
But I will try GetMetadataAsync
and if raises an error [Not found] then I will automatically let the app do [CreateFolderArge] accordingly. What do you think?!

Highlighted

Re: Check if Folder Exists

Dropboxer

Yes, that sounds like a good way to handle the flow of checking for a particular folder and creating it if it doesn't exist.

View solution in original post

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?