Home All Groups Group Topic Archive Search About

Deleting files using wildcards

Author
17 Jul 2006 5:12 AM
BobRoyAce
I know I can use code like follows to delete a file:

My.Computer.FileSystem.DeleteFile(File123.TAB",
FileIO.UIOption.OnlyErrorDialogs,
FileIO.RecycleOption.DeletePermanently)

How can I delete all files matching text including wildcard(s)? For
example, how can I delete all files beginning with "File123" -->
"File123.*"

Author
17 Jul 2006 8:51 AM
John Timney (MVP)
If you recursively search the directory you could quite easily use a regular
expression to identify each file and then use DeleteFile to delete it.

Regards

John Timney (MVP)

Show quoteHide quote
"BobRoyAce" <b***@omegasoftwareinc.com> wrote in message
news:1153113166.402199.252230@35g2000cwc.googlegroups.com...
>I know I can use code like follows to delete a file:
>
> My.Computer.FileSystem.DeleteFile(File123.TAB",
> FileIO.UIOption.OnlyErrorDialogs,
> FileIO.RecycleOption.DeletePermanently)
>
> How can I delete all files matching text including wildcard(s)? For
> example, how can I delete all files beginning with "File123" -->
> "File123.*"
>
Author
17 Jul 2006 3:33 PM
Larry Lard
John Timney (MVP) wrote:
Show quoteHide quote
> "BobRoyAce" <b***@omegasoftwareinc.com> wrote in message
> news:1153113166.402199.252230@35g2000cwc.googlegroups.com...
> >I know I can use code like follows to delete a file:
> >
> > My.Computer.FileSystem.DeleteFile(File123.TAB",
> > FileIO.UIOption.OnlyErrorDialogs,
> > FileIO.RecycleOption.DeletePermanently)
> >
> > How can I delete all files matching text including wildcard(s)? For
> > example, how can I delete all files beginning with "File123" -->
> > "File123.*"
> >
>
> If you recursively search the directory you could quite easily use a regular
> expression to identify each file and then use DeleteFile to delete it.

DirectoryInfo.GetFiles will do the first part of this for you (I only
know this by looking at Reflector's output for Kill, mind...)

--
Larry Lard
Replies to group please
When starting a new topic, please mention which version of VB/C# you
are using
Author
17 Jul 2006 11:55 AM
Michael D. Ober
Shell """%comspec%"" /c del ""File123.*"""

Mike.

Show quoteHide quote
"BobRoyAce" <b***@omegasoftwareinc.com> wrote in message
news:1153113166.402199.252230@35g2000cwc.googlegroups.com...
> I know I can use code like follows to delete a file:
>
> My.Computer.FileSystem.DeleteFile(File123.TAB",
> FileIO.UIOption.OnlyErrorDialogs,
> FileIO.RecycleOption.DeletePermanently)
>
> How can I delete all files matching text including wildcard(s)? For
> example, how can I delete all files beginning with "File123" -->
> "File123.*"
>
Author
17 Jul 2006 3:00 PM
glen.verwey@gmail.com
Or try Kill("File123*.*")


Michael D. Ober wrote:
Show quoteHide quote
> Shell """%comspec%"" /c del ""File123.*"""
>
> Mike.
>
> "BobRoyAce" <b***@omegasoftwareinc.com> wrote in message
> news:1153113166.402199.252230@35g2000cwc.googlegroups.com...
> > I know I can use code like follows to delete a file:
> >
> > My.Computer.FileSystem.DeleteFile(File123.TAB",
> > FileIO.UIOption.OnlyErrorDialogs,
> > FileIO.RecycleOption.DeletePermanently)
> >
> > How can I delete all files matching text including wildcard(s)? For
> > example, how can I delete all files beginning with "File123" -->
> > "File123.*"
> >