Your workflow is unique 👨‍💻 -  tell us how you use Dropbox here.

Forum Discussion

JoshRobbins's avatar
JoshRobbins
Explorer | Level 3
8 years ago
Solved

Client list files completion handler

Hi,

I am successfully listing the contents of a Dropbox folder, however I was wondering whether there is a way to call a completion handler when all the files have been listed?

  • Greg-DB's avatar
    Greg-DB
    8 years ago
    Thanks! In this case, you'd want to run your desired code when the listFolder or listFolderContinue response has hasMore=false. The hasMore value tells you whether or not there are currently any more results to retrieve. If it's false, you know that you've received the entire listing.

    You're already using hasMore to control whether not to call back to listFolderContinue again, so you can expand on that to run some other code when that's done.

4 Replies

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago
    Can you let me know which SDK you're using (if any) and share the code you have so far so I can offer some specific guidance? Thanks in advance!
  • JoshRobbins's avatar
    JoshRobbins
    Explorer | Level 3
    8 years ago

    Hi,

     

    I am using the Swift Version.

     

    Essentially, I am listing the contents of a directory on Dropbox, and filtering for a specific type (which in my case is PNG).

     

    Basically what I need to know, is whether there is a way of being notifiied when the listing of the files has been completed?

     

    Any help would be great :)

     

     func listRemotelySavedFiles(validType:String){
     
            //1. List The Files If Any
            if let client = DropboxClientsManager.authorizedClient {
     
                client.files.listFolder(path: storageVault, recursive: true,
                                        includeMediaInfo: true, includeDeleted: false, includeHasExplicitSharedMembers: false).response(queue: DispatchQueue(label: "Tests"), completionHandler: { (response, error) in
     
     
     
                    if let result = response {
     
     
                        for entry in result.entries {
     
                            if let details = entry as? Files.FileMetadata{
     
                                let entryName  = entry.name as NSString
                                let pathExtension = entryName.pathExtension
     
                                // Only Make Reference To Valid File Types
                                if pathExtension == validType {
     
                                    self.dropBoxDataVault[entry.name] = [entry.pathLower!, details.contentHash!]
                                    print("Unique Hash For Remote File \(entryName) == \(details.contentHash!)")
                                    
                                    
                                }
     
                            }
                            print("Completed *________*")
                        }
     
     
                        //If The User Folder Is Very Big We Need To Call List Continue & Continue To Extract The Data From The Remote Files
                        repeat {
                            client.files.listFolderContinue(cursor: result.cursor).response(completionHandler: { (response, error) in
                                
                                self.remoteFileCount = result.entries.count
                                
                                if let result = response {
                                    
                                    for entry in result.entries {
                                        
                                        let entryName  = entry.name as NSString
                                        let pathExtension = entryName.pathExtension
                                        
                                        // Only Make Reference To Valid File Types
                                        if pathExtension == validType {
                                            
                                            self.dropBoxDataVault[entry.name] = [entry.pathLower!, self.generateRemoteHashTagForFile(path: entry.pathLower!)]
                                            
                                        }
                                        
                                    }
                                    
                                }else{
                                    print("An Error Occured Continuing To List The Folder")
                                }
                            })
                        } while result.hasMore == true
                        
                        
                    } else {
                        print("Error Loading Files")
                        
                    }
                    
                }
                
                
            )}
            
            
        }

     

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    8 years ago
    Thanks! In this case, you'd want to run your desired code when the listFolder or listFolderContinue response has hasMore=false. The hasMore value tells you whether or not there are currently any more results to retrieve. If it's false, you know that you've received the entire listing.

    You're already using hasMore to control whether not to call back to listFolderContinue again, so you can expand on that to run some other code when that's done.
  • koray b.'s avatar
    koray b.
    New member | Level 2
    7 years ago

    Josh,

     

    Can you share the final working code to list all the items in a folder. I have a folder where there are more then 5000 folders.

    Thanks,

    Koray Birand

About Dropbox API Support and Feedback

Node avatar for Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

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, Facebook or Instagram.

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!