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.

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: 

dbxClient.files().listFolder("") only returns 1 folder

dbxClient.files().listFolder("") only returns 1 folder

trithanhnguyen
Helpful | Level 6
Go to solution

I want to list all the files under my member ID. I use the following code and it only show 1 folder even though I have 8 folders starting from root.

 

DbxClientV2 dbxClient = dbxTeamClient.asMember(teamMemberId);
ListFolderResult fileRes = dbxClient.files().listFolder("");
List<Metadata> folders = fileRes.getEntries();
String metaDataCursor = fileRes.getCursor();

while (true)
{
for (Metadata metadata : folders)
{
String type;
String details;
if (metadata instanceof FileMetadata)
{
FileMetadata fileMetadata = (FileMetadata) metadata;
type = "file";
details = "(rev=" + fileMetadata.getRev() + ")";
}
else if (metadata instanceof FolderMetadata)
{
FolderMetadata folderMetadata = (FolderMetadata) metadata;
type = "folder";
details = folderMetadata.getSharingInfo() != null ? "(shared)" : "";
}
else if (metadata instanceof DeletedMetadata)
{
type = "deleted";
details = "";
}
else
{
throw new IllegalStateException("Unrecognized metadata type: " + metadata.getClass());
}

System.out.printf("\t%10s %24s \"%s\"\n", type, details, metadata.getPathLower());
}

if (!fileRes.getHasMore())
{
break;
}
// update cursor to fetch remaining results
fileRes = dbxClient.files().listFolderContinue(metaDataCursor);
folders = fileRes.getEntries();
metaDataCursor = fileRes.getCursor();
}

I then changed my code as the following then it shows the first folder and all the folder and files from that branch but the left 7 folder are not show at all. Any suggestiong to fix it?
TThank you.
DbxClientV2 dbxClient = dbxTeamClient.asMember(teamMemberId);
ListFolderBuilder builder = dbxClient.files().listFolderBuilder("");
builder.withRecursive(true);
ListFolderResult fileRes = builder.start();


 

1 Accepted Solution

Accepted Solutions

Здравко
Legendary | Level 20
Go to solution

@trithanhnguyen wrote:

... Do I need to do some extra setup to list all 3 folders. Thanks.


In all cases you need to set your root to appropriate one using withPathRoot in addition to asMember, if desired folders reside in out of your account's user/member home (as seems it is).

View solution in original post

8 Replies 8

Здравко
Legendary | Level 20
Go to solution

@trithanhnguyen wrote:

I want to list all the files under my member ID. I use the following code and it only show 1 folder even though I have 8 folders starting from root.

...


You are listing all files in your user/member home folder (recursive eventually). If your rest folders are team folders/spaces then you need to enumerate your root. On personal accounts root matches home, but on business account home is only part on all root content!

Hope this gives direction.

trithanhnguyen
Helpful | Level 6
Go to solution

From 8 folders I have in my account, 3 of them I created by myself. So at least the list folder API should return that 3 folders, but it did not. Do I need to do some extra setup to list all 3 folders. Thanks.

Greg-DB
Dropbox Staff
Go to solution

@trithanhnguyen Yes, as Здравко indicated, it sounds like you're looking for the contents of your "team space", but note that by default, API calls operate in the "member folder" of the connected account, not the "team space", so you won't see the contents of your team space when making API calls by default. You can configure API calls to operate in the "team space" instead though. To do so, you'll need to set the "Dropbox-Api-Path-Root" header. You can find information on this in the Team Files Guide. With the Java SDK, you can set that header using withPathRoot.

Здравко
Legendary | Level 20
Go to solution

@trithanhnguyen wrote:

... Do I need to do some extra setup to list all 3 folders. Thanks.


In all cases you need to set your root to appropriate one using withPathRoot in addition to asMember, if desired folders reside in out of your account's user/member home (as seems it is).

trithanhnguyen
Helpful | Level 6
Go to solution

Thank Здравко and Greg,

 

When I set the withPathRoot with my Team Root Namespace then the List Folder API returns all the folders and files under my Team Namespace. I do not want that. I just want to list all the folders and files in my account. There are 3 folders which I created in my personal account. However, when I use this API call:

 

ListFolderResult fileRes = dbxClient.files().listFolderBuilder("").withRecursive(true).start();

It just returns 1 folder and all the contents under that folder.

 

trithanhnguyen
Helpful | Level 6
Go to solution

You can re-produce what I have by create a Dropbox account. Then create 3 folders and upload or create some files and folders under the them. Then write a test program that using the List Folder API on the account. You will see that the API only returns the contents of one folder.

Thanks.

Здравко
Legendary | Level 20
Go to solution

The main question is where you have created all those folders? You seems don't use personal, but business  account! In such a case when you create a folder aside your home folder you create another team folder (out of your home folder). As Greg noted, by default API uses Home folder (the one you are listing only). To list something outside it, simply you need to get out of your home. 😉 That's it. Just use the features mentioned.

trithanhnguyen
Helpful | Level 6
Go to solution

Thank you.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    trithanhnguyen Helpful | Level 6
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?