SwiftyDropbox list folders only
Im using SwiftyDropbox
SDK in my iOS app, I am trying to list folders in my app only, then user can select folder (not 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.
}
record>
{
id = "id:0GMPvYwuVEAAAAAAAAAABw";
name = "Folder A";
"path_display" = "/Folder A";
"path_lower" = "/folder a";
}
how can I find this entry in a folder and it contains a subfolder or not?
source to share
You can select each one entry
inside your loop result.entries
for
as shown
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)
}
}
source to share
The Dropbox API doesn't offer a way to list only folders (although we'll cover it as a feature request), so you'll need to list everything and filter the files.
You can distinguish FileMetadata
, FolderMetadata
and DeletedMetadata
from switch
ing on an object Metadata
as shown in the README .
If you need subfolders, you can specify recursive=true
when calling listFolder
.
source to share