Loading ...

C#: Get filename of all the files inside a directory: | CodeAsp.Net

C#: Get file name of all the files inside a directory:

 /5
0 (0votes)

Considering all subdirectories:

        string directoryPhysicalPath="xxxx";
        string[] files = Directory.GetFiles(directoryPhysicalPath, "*", SearchOption.AllDirectories);
        foreach (string filename in files)
        {
            Console.WriteLine(filename);
        }
        Console.ReadLine();


Considerig root directory only:

        string directoryPhysicalPath="xxxx";
        string[] files = Directory.GetFiles(directoryPhysicalPath, "*", SearchOption.TopDirectoryOnly);
        foreach (string filename in files)
        {
            Console.WriteLine(filename);
        }
        Console.ReadLine();


Comments (no comments yet)

Top Posts