title: aws sdk php for listing s3 folders
body: <p>few things I do know.
  Folders are not a concept of S3 they are merely a zero byte object with key names that use the '/' as prefixes. Assuming that we call them folders and files for simplicity would make my question easier to phrase.</p>
  
  <p>It is possible to do a s3->get_object_list(..) with prefix ="root/" and get all the files/folders. My problem is this.</p>
  
  <p>Given a list of folders and subfolders for e.g.</p>
  
  <pre><code>root/  
  root/folder1/  
  root/folder1/file1.txt  
  root/folder2/ 
  root/folder3/file2.txt
  </code></pre>
  
  <p>How can i list only the folders. I was hoping to prevent listing all files (even in response they need not be returned) but get_object_list in php does not current support commonPrefixes ref: <a href="http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#m=AmazonS3/get_object_list" rel="noreferrer">http://docs.amazonwebservices.com/AWSSDKforPHP/latest/#m=AmazonS3/get_object_list</a>
  even though the doc says so the code clearly does not and using the delimiter will actually only return files in the root folder (prefix)</p>
  
  <p>I am wondering if anyone has used any technique post-response or request based to help with such a situation.</p>
  
  <p>I have already tried every combo of prefix,delimiter and marker i could think of. Not so good with PCRE but sure I could use that I only have one level deep folders but I don't know how to construct one for this case. Since my requests were not working I proceeded to accept the response with all files and folders and hopefully sort it out in php... or so I thought</p>
  
  <p>I have tried in post response:
  dirname() - no use misses out some folders (empty ones), sure I can remove duplicates in array but the problem of missed folder exists
  pathinfo() - behaves the same way as dirname(), assumes that all paths end with filename.
  glob - no luck, same as above.</p>
  
  <p>Since I have already wasted half a day on this I am hoping someone has dealt with this and would care to share:</p>
  
  <p>note: I have no problem doing this in python and boto. But this is not python and I have to do this in PHP for this project.</p>