List all files and directories in a directory + subdirectories

前端 未结 15 1908
陌清茗
陌清茗 2020-12-13 01:46

I want to list every file and directory contained in a directory and subdirectories of that directory. If I chose C:\\ as the directory, the program would get every name of

15条回答
  •  感动是毒
    2020-12-13 02:37

    string[] allfiles = Directory.GetFiles("path/to/dir", "*.*", SearchOption.AllDirectories);
    

    where *.* is pattern to match files

    If the Directory is also needed you can go like this:

     foreach (var file in allfiles){
         FileInfo info = new FileInfo(file);
     // Do something with the Folder or just add them to a list via nameoflist.add();
     }
    

提交回复
热议问题