title: "recursively" grab all files in subfolders in S3
body: <p>I  need help to ‘recursively’ grab files in s3:</p>
  
  <p>For example, I have s3 structure like this:</p>
  
  <pre><code>My-bucket/2018/06/05/10/file1.json
  
  My-bucket/2018/06/05/11/file2.json
  
  My-bucket/2018/06/05/12/file3.json
  
  My-bucket/2018/06/05/13/file5.json
  
  My-bucket/2018/06/05/14/file4.json
  
  My-bucket/2018/06/05/15/file6.json
  </code></pre>
  
  <p>I need to get all files pathes with file name for given bucket:</p>
  
  <p>I tried following method, but it didn’t worked for me (its returning not whole path):</p>
  
  <pre><code>public  List&lt;String&gt; getObjectsListFromFolder4(String bucketName, String keyPrefix) {
          List&lt;String&gt; paths = new ArrayList&lt;String&gt;();
          String delimiter = "/";
          if (keyPrefix != null &amp;&amp; !keyPrefix.isEmpty() &amp;&amp; !keyPrefix.endsWith(delimiter)) {
              keyPrefix += delimiter;
          }
  
          ListObjectsRequest listObjectRequest = new ListObjectsRequest().withBucketName(bucketName)
                  .withPrefix(keyPrefix).withDelimiter(delimiter);
  
          ObjectListing objectListing;
          do {
              objectListing = s3Client.listObjects(listObjectRequest);
              paths.addAll(objectListing.getCommonPrefixes());
              listObjectRequest.setMarker(objectListing.getNextMarker());
          } while (objectListing.isTruncated());
          return paths;
      }
  </code></pre>