title: List all files in (sub)directories in Azure
body: <p>I am developing an azure function using Java. I need to iterate all the files in the following folder</p>
  
  <pre><code>aDirectory/aSubdirectoryWithManyFiles/
  </code></pre>
  
  <p>There are many files in that path,:</p>
  
  <pre><code>aDirectory/aSubdirectoryWithManyFiles/file1
  aDirectory/aSubdirectoryWithManyFiles/file2
  aDirectory/aSubdirectoryWithManyFiles/file3
  aDirectory/aSubdirectoryWithManyFiles/file4
  aDirectory/aSubdirectoryWithManyFiles/file5
  </code></pre>
  
  <p>so I wrote the following code in order to get them all:</p>
  
  <pre><code>// myCloudBlobContainer is a CloudBlobContainer
  // I expected to get all files thanks to the next row
  Iterable&lt;ListBlobItem&gt; blobs = myCloudBlobContainer.listBlobs();
  // The only blob found in the container is the directory itself
  for (ListBlobItem blob : blobs) {
      //log the current blob URI
      if (blob instanceof CloudBlob) {  // this never happens
          CloudBlob cloudBlob = (CloudBlob) blob;
          //make nice things with every found file
      }
  }
  </code></pre>
  
  <p>The only blob iterated in the <code>for</code> is the directory, noone of the expected files. so in logs i get only the following URI:</p>
  
  <pre><code>https://blablablabla.blob.core.windows.net/aDirectory/aSubdirectoryWithManyFiles/
  </code></pre>
  
  <p>What should I do in order to access every file?</p>
  
  <p>And in case I would have more than one subdirectory, as in the following example?</p>
  
  <pre><code>aDirectory/aSubdirectoryWithManyFiles/files(1-5)
  aDirectory/anotherSubdirectoryWithManyFiles/files(6-10)
  </code></pre>
  
  <p>Thanks in advance</p>
  
  <hr>
  
  <p>Edit</p>
  
  <p>In order to make methods testable, the project uses wrappers and interfaces instead of directly using directly a CloudBlobContainer; basically, the CloudBlobContainer is given by <code>CloudBlobClient.getContainerReference("containername")</code></p>
  
  <p>After the answer to this question, I changed teh code to the following
  so I used listBlobs with parameters <code>myCloudBlobContainer.listBlobs("aDirectory", true)</code> and I wrote the following code in order to get them all:</p>
  
  <pre><code>// myCloudBlobClient is a CloudBlobClient
  CloudBlobContainer myCloudBlobContainer = myCloudBlobClient.getContainerReference("containername")
  // I expected to get all files thanks to the next row
  Iterable&lt;ListBlobItem&gt; blobs = myCloudBlobContainer.listBlobs("aDirectory", true); // HERE THE CHANGE
  // No blob found this time
  for (ListBlobItem blob : blobs) { // NEVER IN THE FOR
      //log the current blob URI
      if (blob instanceof CloudBlob) {
          CloudBlob cloudBlob = (CloudBlob) blob;
          //make nice things with every found file
      }
  }
  </code></pre>
  
  <p>But this time, it doesn't go at all in the <code>for</code>...</p>