delete file by filename
Some times, we know the file's name only ,we don't know the extention. but the FileInfo class use the delete method only form filename with the extention . so i find a method that can be delete the perfication file by the file name only.
Notice: Please make sure there is one filename only in this file folder. Otherwise, it can be delete all file with the same filename ,but the different extention.
1
//delete the file in the file folder.
2
//filename
3
string[] str = guids.Split(',');
4
for(int j = 0;j<str.Length;j++)
5
{
6
DirectoryInfo du = new DirectoryInfo("The folder path");
7
FileInfo[] fileInfo = du.GetFiles(str[j]+".*");
8
for(int m=0;m<fileInfo.Length;m++)
9
{
10
fileInfo[m].Delete();
11
}
12
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)