C# 删除某一个目录中所有的txt文件
View Code
1 string path = Environment.CurrentDirectory;
2 string pattern = "*.txt";
3 string[] strFileName = Directory.GetFiles(path, pattern);
4 foreach (var item in strFileName)
5 {
6 File.Delete(item);
7 Console.WriteLine("{0}文件被删除了",item);
8 }
9 Console.ReadLine();