Im using SwiftyDropbox
SDK in my iOS application, im trying to list folders only in my app then user can choose a folder (not a file).
in ViewController
=> viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
guard let dropboxClient = DropboxClientsManager.authorizedClient else{
return
}
let listFolders = dropboxClient.files.listFolder(path: "")
listFolders.response{ response, error in
guard let result = response else{
return
}
for entry in result.entries{
print(entry)
}
}
// Do any additional setup after loading the view, typically from a nib.
}
entry is >
{
id = "id:0GMPvYwuVEAAAAAAAAAABw";
name = "Folder A";
"path_display" = "/Folder A";
"path_lower" = "/folder a";
}
how can i find this entry is folder and it contains sub folder or not?
You can cast each entry
inside of your result.entries
for
loop like this
override func viewDidLoad() {
super.viewDidLoad()
guard let dropboxClient = DropboxClientsManager.authorizedClient else{
return
}
for entry in result.entries{
guard let file = entry as? Files.FolderMetadata else{
return
}
// only folders
print(entry)
// ********* or
gurad let entry is Files.FolderMetadata else{
return
}
// only folders
print(entry)
}
}
The Dropbox API doesn't offer a way to list folders only (though we'll consider it a feature request), so you'll need to list everything and filter out files.
You can distinguish between FileMetadata
, FolderMetadata
, and DeletedMetadata
by switch
ing on the Metadata
object as shown in the README.
If you need subfolders as well, you can specify recursive=true
when calling listFolder
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With