Start 2025 on time and up to date. Seamlessly integrate your calendars into Dropbox with these simple steps.

Forum Discussion

trithanhnguyen's avatar
trithanhnguyen
Helpful | Level 6
3 years ago

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

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();


 

  • Здравко's avatar
    Здравко
    3 years ago

    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).

  • Здравко's avatar
    Здравко
    Legendary | Level 20

    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's avatar
      trithanhnguyen
      Helpful | Level 6

      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's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        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.