One month down in 2025: How are your resolutions coming along? Check out how to get back on track here.
Forum Discussion
JoshRobbins
8 years agoExplorer | Level 3
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?
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?
- 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.
- Greg-DB
Dropbox Staff
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!- JoshRobbinsExplorer | Level 3
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
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.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,945 PostsLatest Activity: 2 hours ago
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!