title: Getting all files in Azure file share (CloudFileDirectory)
body: <p>I'm looking for a C# method that will return all files (in all sub-directories) in an Azure file share.  </p>
  
  <p>Have an example but it throws a run time error.   I've tried the code example below which I got from here however it throws an exception. </p>
  
  <p>I have pasted the code in here but if anyone has a method that walks the entrire Azure directory get gets files that would be great. </p>
  
  <pre><code>CloudFileDirectory dir = fclient.GetShareReference(share.ToString()).GetRootDirectoryReference();
  
  foreach (IListFileItem file in dir.ListFilesAndDirectories())   //.Directory.ListFilesAndDirectories())
  {
      list_subdir(file);
  }   
  </code></pre>
  
  <p>And the method. </p>
  
  <pre><code>public static void list_subdir(IListFileItem list)
  {
      Console.WriteLine("subdir");
      CloudFileDirectory fileDirectory = (CloudFileDirectory)list;
      IEnumerable&lt;IListFileItem&gt; fileList = fileDirectory.ListFilesAndDirectories();
  
      foreach (IListFileItem listItem in fileList)
      {
          if (listItem.GetType() == typeof(Microsoft.WindowsAzure.Storage.File.CloudFileDirectory))
          {
              list_subdir(listItem);
          }
          else
          {
              Console.WriteLine(listItem.Uri.Segments.Last());
          }
      }
  }
  </code></pre>
  
  <p>"   at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.d__1<code>1.MoveNext() 
  in C:\Program Files (x86)\Jenkins\workspace\dotnet-split-pr-master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 82
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.&lt;&gt;c__DisplayClass0_0</code>1.b__0() in 
     C:\Program Files (x86)\Jenkins\workspace\dotnet-split-pr-master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 41</p>