1

i'm using a dropbox api, and this is a part of my script:

$folders = $dropbox->GetMetadata("");

echo '<pre>';
print_r($folders).'
echo </pre>';

It returns an array like this:

stdClass Object
(
    [hash] => 9539e595b82fce68ee1bcda37a23848f
    [thumb_exists] => 
    [bytes] => 0
    [path] => /
    [is_dir] => 1
    [icon] => folder
    [root] => dropbox
    [contents] => Array
    (
        [0] => stdClass Object
            (
                [bytes] => 0
                [rev] => e8b1169b0b4
                [revision] => 3723
                [icon] => folder_camera
                [path] => /Camera Uploads
                [is_dir] => 1
                [thumb_exists] => 
                [root] => dropbox
                [modified] => Sun, 04 Jan 2015 08:12:03 +0000
                [size] => 0 bytes
            )

        [1] => stdClass Object
            (
                [rev] => e5a1169b0b4
                [thumb_exists] => 1
                [path] => /DSC_0346.JPG
                [is_dir] => 
                [client_mtime] => Sun, 14 Dec 2014 08:52:25 +0000
                [icon] => page_white_picture
                [bytes] => 1777550
                [modified] => Sun, 14 Dec 2014 08:52:25 +0000
                [size] => 1.7 MB
                [root] => dropbox
                [mime_type] => image/jpeg
                [revision] => 3674
            )

But i just cant figure out how i list only all the directory names in one list. The directory names are named [path] in the array.

Can someone explain it to me?

1
  • use the complete form of foreach($array as $key => $value) then compare $key === "path" Commented Jan 8, 2015 at 18:33

3 Answers 3

3

The question is not 100% clear.

So if you want to list folders only do this:

$folders = $dropbox->GetMetadata("");

echo '<pre>';
foreach($folders->contents as $item) {
  if ($item->is_dir==1) {
    echo $item->path.'<br />';
  }
}

echo '</pre>';

hope my guess is what you are asking for

Sign up to request clarification or add additional context in comments.

Comments

1

You need to loop over the contents property of your object as that is the array containing the folder objects where the path and is_dir properties are stored:

foreach ($folders->contents as $obj)
{
  if ($obj->is_dir === 1)
  {
    echo $obj->path;
  }
}

1 Comment

Not all folder contents are directories. You would need to check for the is_dir flag within the contents array
0

Try this:

$paths[]  = $folders->path ; //return the root path(/)

foreach($folders->contents as $pathObj)
{
   if ($pathObj->is_dir==1) {   

       $paths[]  = $pathObj->path ;
   }
}

print_r($paths);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.