Get List of all files from all folder from Azure DataLake using C#

manish verma 421 Reputation points
2021-12-02T06:58:39.527+00:00

HI All,

Can we have some example to get list of all files from all folder from Azure Data Lake using .NET(C#).

Azure Data Lake Storage
Azure Data Lake Storage
An Azure service that provides an enterprise-wide hyper-scale repository for big data analytic workloads and is integrated with Azure Blob Storage.
1,349 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,436 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,279 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. deherman-MSFT 33,626 Reputation points Microsoft Employee
    2021-12-02T20:25:18.583+00:00

    @manish verma You should be able to use FileSystemClient.GetPathsAsync to achieve this. On our GitHub page we have sample code which allows you to list all the directories. Combining that with sample that lists all the directory contents should get you the results you need.

    Hope this helps! Let us know if you have further questions or issues and we will be happy to assist.

    -------------------------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

  2. manish verma 421 Reputation points
    2021-12-03T13:20:20.583+00:00

    Thanks for replay ,

    this is async method, how we call this method in Main class to run program.

    public async Task ListFilesInDirectory(DataLakeFileSystemClient fileSystemClient)
    {
    IAsyncEnumerator<PathItem> enumerator =
    fileSystemClient.GetPathsAsync("my-directory").GetAsyncEnumerator();

    await enumerator.MoveNextAsync();  
    
    PathItem item = enumerator.Current;  
    
    while (item != null)  
    {  
        Console.WriteLine(item.Name);  
    
        if (!await enumerator.MoveNextAsync())  
        {  
            break;  
        }  
    
        item = enumerator.Current;  
    }  
    

    }

    if i call like -ListFilesInDirectory(fileSystemClient); like other method it is error out

    i use a console application in .net in C#- to run this method in main program error out

    i use reference from here-https://learn.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-directory-file-acl-dotnet#list-directory-contents

    0 comments No comments