By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,149 Members | 885 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,149 IT Pros & Developers. It's quick & easy.

Delete files

P: n/a
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.
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
foreach(string sFile in System.IO.Directory.GetFiles("D:\\"))
{
if (sFile.ToUpper().EndsWith(".LNK"))

System.IO.File.Delete(sFile);
}

--
gani


"Krazitchek" <kr********@hotmail.com> wrote in message
news:02****************************@phx.gbl...
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.

Nov 15 '05 #2

P: n/a
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

"Krazitchek" <kr********@hotmail.com> wrote in message
news:02****************************@phx.gbl...
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.

Nov 15 '05 #3

P: n/a
Thank you.
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.