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: 

Check if Folder Exists

Check if Folder Exists

evry1falls
Collaborator | Level 8
Go to solution

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

Greg-DB
Dropbox Staff
Go to solution

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

Greg-DB
Dropbox Staff
Go to solution

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.

evry1falls
Collaborator | Level 8
Go to solution

@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?!

Greg-DB
Dropbox Staff
Go to solution

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.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    evry1falls Collaborator | Level 8
What do Dropbox user levels mean?