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: 

Client list files completion handler

Client list files completion handler

JoshRobbins
Explorer | Level 3
Go to solution
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?

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution
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.

View solution in original post

4 Replies 4

Greg-DB
Dropbox Staff
Go to solution
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
Explorer | Level 3
Go to solution

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
Dropbox Staff
Go to solution
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.
New member | Level 2
Go to solution

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

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    koray b. New member | Level 2
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    JoshRobbins Explorer | Level 3
What do Dropbox user levels mean?