Rajanikant Hawaldar
How do I list all files of a directory?

How do I list all files of a directory?

By Rajanikant Hawaldar in Python on Oct 10 2020
  • Kiran Mohanty
    Oct, 2020 13

    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);

    • 1
  • Richard Robin
    Dec, 2021 15

    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

    • 0
  • Guest User
    Oct, 2020 19

    ls -a

    • 0
  • Guest User
    Oct, 2020 16

    or ls -a for hidden files

    • 0
  • Varun Setia
    Oct, 2020 14

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

    • 0
  • Varun Setia
    Oct, 2020 14

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

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS