Delete files

  • Thread starter Thread starter Krazitchek
  • Start date Start date
K

Krazitchek

Hi, how do i do to delete files with a specific extension
(like *.lnk).

I try File.Delete(@"e:\test\\*.lnk) but it does not work,
not the good way i guess...

Help please, thanks.
 
foreach(string sFile in System.IO.Directory.GetFiles("D:\\"))
{
if (sFile.ToUpper().EndsWith(".LNK"))

System.IO.File.Delete(sFile);
}
 
Krazitchek,
To borrow gani's code:

foreach(string sFile in System.IO.Directory.GetFiles(@"e:\test\", "*.lnk"))
{
System.IO.File.Delete(sFile);
}

The Directory.GetFiles function returns a string array of all the files in a
folder, the method is overloaded for an optional pattern.

As far as I can tell the array always includes the path passed to GetFiles.

Hope this helps
Jay
 
Back
Top