473,320 Members | 1,993 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Delete files

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
3 20014
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
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
Thank you.
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Ben | last post by:
Greetings, I am looking for a way to search for and delete files based on a pattern mask. For example, the search method would find all files matching a certain pattern containing wildcards (e.g....
5
by: Jobs | last post by:
Hello All, I want to delete all files in a directory. I am making a backup copy of all files in the directories say c:\abc by reading and writing to a file. After making a backup copy I want to...
2
by: U C | last post by:
Hi, Can i delete files in cdump folder. Whats the basic use of having files in cdump folder. Is there any need to take backup when deleting the same. I am having solaris if we can delet then what...
5
by: Raj | last post by:
Hi all, Can anyone help me with a script which would delete files or move them to a different folder at some scheduled time..! Please.....!!! Thanks in advance...
6
by: Sonoman | last post by:
Hi all: I would like to find out how to write a small program that deletes files. I want to be able to delete all files from a known directory (i.e. cookies, temp files, etc.) regardless of type...
3
by: Scott_Tuttle | last post by:
I'm trying to delete files with strange characters in the names but csharp doesnt seem to be able to see them at all. Solution??
1
by: Keith Henderson | last post by:
It seems that I will soon have to write a windows service (or if there's something more appripriate?) that will delete files off of a hard drive. Here's an example, a file will be placed in a...
2
by: David | last post by:
How can I delete files at once? Like: " delete C:\MyFiles.* "
1
by: amituts | last post by:
Hi! I need a script which delete files in a directory when there are more than 8 files exist in that directory. It should delete oldest file and 3 latest file should be remains in that directory. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.