cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Whether you are transferring a single drive, a team or an entire organization, Movebot's cloud migration tool has been built to make your Dropbox migration simple - learn all about it 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

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

Re: Check if Folder Exists

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

Re: Check if Folder Exists

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

Re: Check if Folder Exists

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

Re: Check if Folder Exists

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

Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    evry1falls Collaborator | Level 8
What do Dropbox user levels mean?
Need more support?