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

Algorythm to delete all files under a directory and subs based on wildcard

Does someone have or know of an algorythm (method) that will delete all
files under a give directory and its subdirectories based on a wildcard
mask?

I can use this for one directory

for each file in Directory.GetFiles("pic1.*")
file.Delete()

but will need to use a recursive algorythm to get all its subdirectories

I thought I would try this news group before I went and wrote my own.

Thanks for your help

Earl
Nov 16 '05 #1
1 2382

Earl,

The code below will help you scan a directory and it's subdirectorys
and let you check the files. You could implement the wildcard matches
with StartsWith, EndsWith and IndexOf depending on the number of
wldcards and thier position, or translate it to a regexpression.

public class DriveScanner
{
private DriveScanner()
{
}
public static void Scan(string drive)
{
DirectoryInfo dirInfo =
new DirectoryInfo(drive);
DriveScanner.Scan(dirInfo);
}

public static void Scan(DirectoryInfo dirInfo)
{
Console.WriteLine("Entering directory {0}", dirInfo.FullName);
FileInfo[] files = dirInfo.GetFiles();

foreach(FileInfo file in files)
{
Console.WriteLine(file.Name);
//
// Check filename and to your work
//
}

foreach(DirectoryInfo info in dirInfo.GetDirectories())
DriveScanner.Scan(info);
}
}
"Earl Teigrob" <ea******@hotmail.com> skrev i meddelandet
news:%2******************@TK2MSFTNGP12.phx.gbl...
Does someone have or know of an algorythm (method) that will delete all
files under a give directory and its subdirectories based on a wildcard
mask?

I can use this for one directory

for each file in Directory.GetFiles("pic1.*")
file.Delete()

but will need to use a recursive algorythm to get all its subdirectories

I thought I would try this news group before I went and wrote my own.

Thanks for your help

Earl

Nov 16 '05 #2

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....
1
by: Earl Teigrob | last post by:
Does someone have or know of an algorythm (method) that will delete all files under a give directory and its subdirectories based on a wildcard mask? I can use this for one directory for each...
2
by: David | last post by:
How can I delete files at once? Like: " delete C:\MyFiles.* "
2
by: Ken Yee | last post by:
First a little background: I've written an httphandler to handle wildcard extensions (i.e., I want to handle all URLs that come in rather than just URLs w/ a specific file extension so I can give...
3
by: richardkreidl | last post by:
I have the following module that I delete old files based on how old they are: Sub Main() Dim First_Date As String = Date.Today.AddDays(-7) Dim Archive_Files() As String =...
6
by: David Thielen | last post by:
Hi; I have tried both: <add verb="*" path="html-image\*.jpg" type="BitmapView"/> and <add verb="*" path="html-image\*" type="BitmapView"/> But neither works. In both cases I just get file...
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: =?Utf-8?B?UGF1bA==?= | last post by:
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...
15
by: Andy B | last post by:
I need to count files in a certain directory that has the string -Contract Template.xml at the end of it. How would I do this?
7
by: Apros | last post by:
Okay, this is what I need to do, and I keep getting confused. I need to remove all files in a folder, then delete the folder, it's part of an installer I'm making, and it creates a directory, I just...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.