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

File.Delete and Wildcard Extension

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.