6
Reply

How do I list all files of a directory?

How do I list all files of a directory?

    You can try below code.

    1. DirectoryInfo d = new DirectoryInfo(@"D:\test");//your folder path
    2. FileInfo[] Files = d.GetFiles("*.txt");
    3. string str = "";
    4. foreach(FileInfo file in Files )
    5. {
    6. str = str + ", " + file.Name;
    7. }
    8. Console.WriteLine(str);

    If you need a list of files in a given directory, for example, so you can loop through them, how can you get a clean list of file names? On a windows based PC, you can use dos commands. You’ll need to start by accessing the command line. Below are directions on how to do that in Windows. Note that if you are using Stata, you can access the command line by starting the command with a “!” in other words, do get a list of files in the current directory one would type “! dir”. kitchenremodeltacomawa.com

    ls -a

    or ls -a for hidden files

    In python os.listdir(), this will return everything in that directory. We can filter the records after that to only show files.

    Directory.GetFiles([path]), this will return array of files.