C#删除文件夹里的某个文件或者批量删除指定的文件
假如有一个文件夹里有6个文件
文件命名中,有三个A开头的文件,有三个B开头的文件
现在我要实现,凡是B开头的文件都要删除,只留下A开头的文件
这时候就可以这样实现
using System.IO;
foreach (string d in Directory.GetFileSystemEntries(fileName))
{
if (File.Exists(d))
{
string me = Path.GetFileNameWithoutExtension(d);
if (me.StartsWith("B"))
{
File.Delete(d);
}
}
}
fileName是文件夹的路径