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
 3string[] str = guids.Split(',');    
 4for(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}
        

posted on 2006-09-29 10:34  广思  阅读(247)  评论(0编辑  收藏  举报

导航