cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

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

hbuuutag
Explorer | Level 4
Go to solution

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!

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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.

View solution in original post

2 Replies 2

Greg-DB
Dropbox Staff
Go to solution

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
Explorer | Level 4
Go to solution

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

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    hbuuutag Explorer | Level 4
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?