cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We just wanted to say thank you! Check out our customer appreciation video 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: 

Re: How to display folders in the file list Dropbox API (Swift 5)

How to display folders in the file list Dropbox API (Swift 5)

VyacheslavB
Helpful | Level 5
Go to solution

I get a list of the user's files and then filter it to show only the music files. But I also want to see subfolders. How should I set up my filter for this? Could you help me.
My function where I get the list of files looks like this:Screen Shot 2020-08-25 at 12.03.28.png

I also want to be able to enter a subfolder, as I understand it, for this I need to insert the path to the subfolder in path: "/ someFolder". But how can I get this path?

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

To check if a particular entry is a file or a folder, you can check the type of the entry, such as by switching on it as shown in this example.

View solution in original post

11 Replies 11

Greg-DB
Dropbox Staff
Go to solution

If you want to access subfolders as well when listing a folder, you can set recursive:true when calling listFolder. That will make the results include nested entries as well. 

 

Alternatively you can call separately to specifically list a particular subfolder, by passing in the path. To do so, get and pass in the relevant Metadata.pathLower.

 

Either way, make sure you also have listFolderContinue implemented (as documented under listFolder) to make sure you're getting all of the entries. 

VyacheslavB
Helpful | Level 5
Go to solution

If I want to use the second option (using the folder path), then how do I display only music files and folders? I use .hasSuffix for sorting, but then I cannot see the folder in the list.
How can I separate folders from files in code. A file has its extension, but how to filter so that folders are visible in the list too?

As you understand, I want to have some attribute to know this is folder or file.

Greg-DB
Dropbox Staff
Go to solution

To check if a particular entry is a file or a folder, you can check the type of the entry, such as by switching on it as shown in this example.

VyacheslavB
Helpful | Level 5
Go to solution

When I try to use code from example, I get a warning: Cast from 'Files.ListFolderResult' to unrelated type 'Files.FileMetadata' always fails.
Maybe there is another option or a better example? Or am I doing something wrong?

Screen Shot 2020-08-27 at 09.14.35.png

Greg-DB
Dropbox Staff
Go to solution

You're trying to cast the ListFolderResult itself, which isn't a type of Metadata. You should instead be casting each Metadata object in the ListFolderResult.entries array.

VyacheslavB
Helpful | Level 5
Go to solution

Thanks, it really helped me!

Mimi_89
New member | Level 2
Go to solution
Documentaions

roggerCorrea
Explorer | Level 3
Go to solution

Hi Viyalexhab,

 

How do you declare the variable fileList? 

I'm trying t do the same thing, so I can append the files to it. But I can't figure out what type of variable you need to use to be able to append. 

 

Thanks!

roggerCorrea
Explorer | Level 3
Go to solution

I get this error, does anybody knows what to do?

roggerCorrea_0-1667445846137.png

 

Need more support?