You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

hbuuutag's avatar
hbuuutag
Explorer | Level 4
6 years ago

How do I iterate through all files and folders and list the metadata?

Trying to make an app that gets and lists all the metadata from Dropbox account.

I am successfully able to get to the parent folder and print that info but cannot figure out how to get the API to go into the folder and then list the files and/or go into the next nested folder and list get those files. I imagine there is some method but I've been prowling the documentation for a day or two now and can't figure it out!

async Task GetFileList(string folderPath)
{
string apiToken = "dummy info";

using (var dbx = new DropboxClient(apiToken))
{
var listOfFolders = await dbx.Files.ListFolderAsync(string.Empty);
var currentFilePath = "";

DropboxFile dropboxFile = new DropboxFile();
foreach (var item in listOfFolders.Entries)
{
if (item.IsFolder)
{

Console.WriteLine("D {0}/", item.Name);
item = currentFilePath;

foreach (var metadata in listOfFolders.Entries.Where(i => i.IsFile))
{

string line = item.PathLower + "/" + item.Name + " " + item.AsFile.Size + item.AsFile.PropertyGroups;

Console.WriteLine(line);
}
else
{
Console.WriteLine("THESE ARE FILES NOW");
}

}

}
}
}

 

Be kind, I'm very new to c# :) Thank you!

  • It looks like you're already on the right track here. If you want to list everything under the root, you start by calling ListFolderAsync with the empty string as the 'path'. If you want to get nested entries too, you should set the 'recursive' parameter to true.

    Either way, ListFolderAsync isn't guaranteed to give you everything. You'll need to check the returned ListFolderResult.HasMore and call back to ListFolderContinueAsync if it's true, and so on. Check out the ListFolderAsync documentation for more information on how to process this.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    It looks like you're already on the right track here. If you want to list everything under the root, you start by calling ListFolderAsync with the empty string as the 'path'. If you want to get nested entries too, you should set the 'recursive' parameter to true.

    Either way, ListFolderAsync isn't guaranteed to give you everything. You'll need to check the returned ListFolderResult.HasMore and call back to ListFolderContinueAsync if it's true, and so on. Check out the ListFolderAsync documentation for more information on how to process this.

    • hbuuutag's avatar
      hbuuutag
      Explorer | Level 4

      Solved! Setting the recursive parameter to true was what I was missing ultimately. Thanks for your quick response!

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API

Make connections with other developers

797 PostsLatest Activity: 2 days ago
199 Following

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!