We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here. 

Forum Discussion

evry1falls's avatar
evry1falls
Collaborator | Level 8
5 years ago

Check if Folder Exists

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
  • Greg-DB's avatar
    Greg-DB
    5 years ago

    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.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    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's avatar
      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?!

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        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.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,876 PostsLatest Activity: 6 hours ago
325 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!