none
Recursive read of all files in azure share. RRS feed

  • Question

  • Hello, 

    I need to read all files (type CloudFile) from an Azure file share.  Just like ona regular file system the files I need could be in the root or many levels down.  I have this but it only reads one level down so I think it needs to be recursive.  So instead pf the inner foreach loop do I just call the same method?  Also, are there any issues with the number of times a method can call itself? 

    Thanks 

    Sunday, March 24, 2019 5:37 PM

All replies

  • Hello,

     Walking a Directory structure is simply.  From the Root, the call gets the Directory contents.

    Depending on security, any calls to sub-directories could be limited, so you must handle any

    errors.  Other than that, just call the same method with the sub-directory path, see example;

     N:\ <- Root

     N:\Budget <- Sub-directory

     

     Unless the Azure path naming is different than standard NTFS then all calls should work.

     

     I recommend using the Stack Class to hold the Directory Tree structures because you can

    manage push/pop object easier but any container ( List, Dictionary, etc ) class will work also.

     

     The logical operations is, read Root contents into container. Scan container for objects that

    have Directory attribute set. Then append the object to Root and read contents.  Depending

    on the nested structure the tree could be large and time consuming if read all at once.

     

     Helpful Links

     https://www.codeproject.com/Articles/597939/ModelingplusaplusDirectoryplusStructureplusonplusA

    https://stackoverflow.com/questions/2619007/windows-azure-how-to-create-sub-directory-in-a-blob-container

    https://www.michaelcrump.net/azure-tips-and-tricks79/

    http://johnatten.com/2013/05/24/modeling-a-directory-structure-on-azure-blob-storage/

     Hope this helps. :)

    Sunday, March 24, 2019 6:26 PM
  • Hi

    Thank you for posting here.

    Based on your question, you want to read all the files from an Azure file share.

    The following link could help you.

    https://stackoverflow.com/questions/51305765/how-to-get-all-files-which-is-inside-sub-folders-in-azure-file-share-storage-c

    Best regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 25, 2019 7:18 AM
    Moderator
  • Hello, 

    Thanks for both answers.  

    I have had a look at the stackoverflow example in the past and to be honest I thought there was a way to do this all within on method.  That said I cannot find anything this morning. 

    My method now takes a single argument which is the Azure file share.   This share contains 17 files and five folders, however my code only finds the five folders. 

    internal List<IListFileItem> GetFiles(CloudFileDirectory directory)
    {
        List<IListFileItem> files = new List<IListFileItem>();
        foreach (IListFileItem file in directory.ListFilesAndDirectories())  // src.Directory - CloudFileDirectory 
        {
              if (file is CloudFileDirectory)
              {
                  CloudFileDirectory subdir = (CloudFileDirectory)file;
                  GetFiles(subdir);
              }
              else
              {
                  files.Add(file);
              }
        }
    
        return files;
    }

    I know I'm missing the obvious here :-( 




    Monday, March 25, 2019 10:48 AM
  • Hi

    Thanks for the feedback.

    Due to lacking the Azure file share, I could not test your code. However, I find the following link is similar to your problem, it may be helpful for you.

    https://stackoverflow.com/questions/38520442/get-files-recursively-from-azure-file-storage-using-c-sharp

    Best Regards,

    Jack



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 26, 2019 8:12 AM
    Moderator