Have an example?
Main Topics
Browse All TopicsC# VS 2008 Windows App - Trying to do a wildcard delete of numerous files or directories.
System.IO.File.Delete(@"c:
System.IO.Directory.Delete
Neithier of these work - report invalid chacter? Is there a way around this (easy way)?
Karl66
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi,
There are a couple solutions you could use here. If you want to delete all files in the folder, and the folder included, you could use System.IO.Directory.Delete
If you want to delete only the files in the directory, but keep the directory, you could do this:
string[] files = System.IO.Directory.GetFil
foreach ( string file in files ) {
System.IO.File.Delete(file
}
Anyone interested in a wild card delete of all files of the same extension in a directory read on. This example deletes all *.doc files in the application path but can be tailored to do the same for any path.
C#
// Finds folder path of current assembly,
TargetPath = System.Reflection.Assembly
TargetPath = TargetPath.Substring(0, TargetPath.LastIndexOf("\\
// Deletes all *.doc files in dir
string[] fileEntries = Directory.GetFiles(@Target
foreach (string fileName in fileEntries)
{
File.Delete(fileName);
}
Business Accounts
Answer for Membership
by: angelIIIPosted on 2008-03-25 at 14:41:30ID: 21206547
you cannot delete with "wild character".
you have to list the files and delete one by one
OR
run a command line to run "DEL c:\wtemp2\*.*"