title: How to get all files which is inside sub-folders in azure file share storage c#?
body: <p>I want to copy all files which are inside sub-folders.</p>
  <p>folder structure -</p>
  <p>Source\Folder1\Data\file1.txt</p>
  <p>Source\Folder1\Data\file2.txt</p>
  <p>Source\Folder1\Data\Temp1\temp1.txt</p>
  <p>Source\Folder1\Data\Temp1\temp2.txt</p>
  <p>I have following code but I'm only getting <code>root and its sub-folders not inside it</code>.</p>
  <p>I want recursive code. Thanks to @Compufreak for recursive code
  I'm still unable to copy files because source is source folder not current.</p>
  <pre class="lang-cs prettyprint-override"><code>public static void list_file()
  {
      //***** Get list of all files/directories on the file share*****//
      CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings[&quot;storageConnectionString&quot;]);
      CloudFileClient fileClient = cloudStorageAccount.CreateCloudFileClient();
      CloudFileShare fileShare = fileClient.GetShareReference(ConfigurationManager.AppSettings[&quot;shareName&quot;]);
  
      IEnumerable&lt;IListFileItem&gt; fileList = fileShare.GetRootDirectoryReference().ListFilesAndDirectories(ConfigurationManager.AppSettings[&quot;sourceName&quot;]);
  
      CloudFileDirectory rootDir = fileShare.GetRootDirectoryReference();
      CloudFileDirectory sourceDir = rootDir.GetDirectoryReference(ConfigurationManager.AppSettings[&quot;sourceName&quot;]);
      CloudFileDirectory destinationDir = rootDir.GetDirectoryReference(ConfigurationManager.AppSettings[&quot;destinationName&quot;]);
  
      // Print all files/directories listed above.
      foreach (IListFileItem listItem in fileList)
      {
          // listItem type will be CloudFile or CloudFileDirectory.
          Console.WriteLine(listItem.Uri.Segments.Last());
          Console.WriteLine(listItem.GetType());
          if (listItem.GetType() == typeof(Microsoft.WindowsAzure.Storage.File.CloudFileDirectory))
          {
              list_subdir(listItem, sourceDir, destinationDir);
          }
      }
  }
  
  public static void list_subdir(IListFileItem list, CloudFileDirectory sourceDir, CloudFileDirectory destinationDir)
  {
      Console.WriteLine(&quot;subdir&quot;);
      CloudFileDirectory fileDirectory = (CloudFileDirectory)list;
      IEnumerable&lt;IListFileItem&gt; fileList = fileDirectory.ListFilesAndDirectories();
  
      // Print all files/directories in the folder.
      foreach (IListFileItem listItem in fileList)
      {
          // listItem type will be CloudFile or CloudFileDirectory.
          if (listItem.GetType() == typeof(Microsoft.WindowsAzure.Storage.File.CloudFileDirectory))
          {
              list_subdir(listItem,sourceDir,destinationDir);
          }
          else
          {
              Console.WriteLine(listItem.Uri.Segments.Last());
              // move file to destination
              // Get a reference to the file we created previously.
              CloudFile sourceFile = sourceDir.GetFileReference(listItem.Uri.Segments.Last());
  
              // Ensure that the source file exists.
              if (sourceFile.Exists())
              {
                  // Get a reference to the destination file.
                  CloudFile destFile = destinationDir.GetFileReference(listItem.Uri.Segments.Last());
  
                  // Start the copy operation.
                  destFile.StartCopy(sourceFile);
  
                  // Write the contents of the destination file to the console window.
                  Console.WriteLine(destFile.DownloadText());
              }
          }
      }
  }
  </code></pre>