473,545 Members | 937 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 20049
foreach(string sFile in System.IO.Direc tory.GetFiles(" D:\\"))
{
if (sFile.ToUpper( ).EndsWith(".LN K"))

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

--
gani


"Krazitchek " <kr********@hot mail.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.Direc tory.GetFiles(@ "e:\test\", "*.lnk"))
{
System.IO.File. Delete(sFile);
}

The Directory.GetFi les 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********@hot mail.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
15630
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. *FILE29*.TXT). I'm looking for a way to do this in either Visual Basic or C(++). Thanks!
5
14140
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 delete these files. I am using following code: // get list of all files in the directories
2
28390
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 is the command for the same. thanks Regards umesh
5
13266
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
11601
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 and name, "or" may be by extension. This way I could have it run on start up and I will have my computer free of junk every time I reboot. What...
3
2607
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
2339
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 directory, at the time it is placed there, a row will be inserted into an RDBMS table which gives the filename, the location (could be on various...
2
1656
by: David | last post by:
How can I delete files at once? Like: " delete C:\MyFiles.* "
1
1800
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. file format : read_story_12_03_2010.zip read_story_13_03_2010.zip Thanks in advance for ur help.
0
7467
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7807
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7419
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.