473,408 Members | 1,982 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,408 software developers and data experts.

File.Delete and Wildcard Extension

I have a folder with the following files:

a.doc
a.csv
a.pdf

Sometimes all three files are there. Sometimes there is only one file there.

Is there a File.Delete command that I can use that would delete all the
files regardless of how many there were, and regardless of their file
extension?

I was thinking of using some type of wildcard (like a*.*). Something like:

File.Delete(Server.MapPath("docs/" & sPartialFileName & "*.*"))

But I get errors with this statement.

Anyone have a good way of doing this?

Jun 27 '08 #1
1 2190
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:69**********************************@microsof t.com...
>I have a folder with the following files:

a.doc
a.csv
a.pdf

Sometimes all three files are there. Sometimes there is only one file
there.

Is there a File.Delete command that I can use that would delete all the
files regardless of how many there were, and regardless of their file
extension?
No. You need to retrieve a collection of the files that you want to delete
and then delete them one by one:

foreach (string strFile in Directory.GetFiles(Server.MapPath("docs/" &
sPartialFileName & "*.*"))
{
File.Delete(strFile);
}
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #2

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

Similar topics

1
by: usura | last post by:
Hi I am building an upload script that overwrites any file with the same name, however the file could be a jpg, gif, bmp etc Using 'fso.FileExists ' i can find if a file of the same name...
3
by: Lou | last post by:
Question: I can't seem to get file.exists(filename) to return true when I search using wildcards, and I know there's a file in that dir with that extension. here's the path dim yesno as...
3
by: Chung Leong | last post by:
Here's the rest of the tutorial I started earlier: Aside from text within a document, Indexing Service let you search on meta information stored in the files. For example, MusicArtist and...
5
by: kenny | last post by:
I want to delete files but I also want to set the wildcards manually. Look at this example: If TextBox1.Text = "" Then Else For Each foundFile As String In...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
11
by: comp.lang.php | last post by:
Once again, I thought my class method deleteZip() would do the trick, but it never deletes any .zip* file found in a directory: /** * Delete any latent ZIP files found in this album. This...
1
by: mdufour | last post by:
Hi all, I am working on a VPP and i would need some help. I built my VPP using the model in the Sept 06 issue of Visual Studio Magazine article RESTful ASP.NET app (Page 46). I got the code...
4
by: bill | last post by:
I have a directory into which I upload pictures. I know the entire file name other than the extension. file_exists will return true when I give it a wildcard extension, but I can't figure out...
5
by: Krustov | last post by:
I have the following list of image files . When searching the latest (numbered file) in this particular case its background_4.*** and its a .jpg file - but - the latest file in the list could...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.