title: How can I non-recursively browse the contents of a directory with the AWS S3 API?
body: <p>Say I have the following directories and files in an Amazon S3 bucket (files are in <strong>bold</strong>):</p>
  
  <ul>
  <li>bucketname/</li>
  <li>bucketname/folder1/</li>
  <li>bucketname/folder1/<strong>foobar.txt</strong></li>
  <li>bucketname/folder1/subfolder1/</li>
  <li>bucketname/folder1/subfolder1/<strong>hello.txt</strong></li>
  <li>bucketname/folder1/subfolder2/</li>
  <li>bucketname/folder1/subfolder2/<strong>world.txt</strong></li>
  <li>bucketname/folder1/subfolder2/subsubfolder1/</li>
  <li>bucketname/folder1/subfolder2/subsubfolder1/<strong>file.txt</strong></li>
  </ul>
  
  <p>How can I list all objects and <em>immediate</em> subdirectories of a given directory with the .NET AWS S3 API, without recursively getting everything below that directory? In other words, how can I "browse" the contents of a directory at a single level?</p>
  
  <p>For example, imagine I want to browse the contents of <code>bucketname/folder1/</code>. What I would like to see is the following:</p>
  
  <ul>
  <li>bucketname/folder1/<strong>foobar.txt</strong></li>
  <li>bucketname/folder1/subfolder1/</li>
  <li>bucketname/folder1/subfolder2/</li>
  </ul>
  
  <p>...and nothing else. I don't want to list the files and directories in <em>subdirectories</em>, I just want to list the files and subdirectories at the <code>folder1</code> level.</p>
  
  <p>Is there a way to apply filters to a single AWS API call so that it doesn't return <em>everything</em> and force me to manually parse only what I need?</p>
  
  <p>I've found that this code let's me get just the immediate subdirectories (as intended), but I can't figure out how to include the immediate <em>files</em> too:</p>
  
  <pre><code>var request = new ListObjectsRequest()
      .WithBucketName("bucketname")
      .WithPrefix(@"folder1/")
      .WithDelimiter(@"/");
  
  using (var client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey))
  using (var response = client.ListObjects(request))
  {
      foreach (var item in response.CommonPrefixes)
      {
          /* ... */
      }
  }
  </code></pre>