×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

File.Exists(), File.Delete() wildcards

File.Exists(), File.Delete() wildcards

File.Exists(), File.Delete() wildcards

(OP)
Colleagues,

Does the function in subject takes wildcards?
I have the code

CODE --> .NET

If File.Exists(lcSelectedDir & "*.*") Then
   ' Some code
End If 

and it never gets inside If - End If structure even though there are a slew of files in that lcSelectedDir.
I have found that Directory.GetFiles(String, String) can be used instead (tested, it worked.)
However, I also need somethihng like Delete(sPath & "*.*"), that is again: wild cards.
Apparently, File object cannot work with wildcards.
Additionally, Directory object has no Delete() method, and I need something like that.
I could've roll-er-own function, e.g. DeleteFiles(sPath & "*.*"), but I hope there is already such thing, and I wouldn't be "re-inventing the wheel".
Hence teh Q.:

Is there, in .NET, a function Delete() files that takes wildcards?

TIA!

Regards,

Ilya

RE: File.Exists(), File.Delete() wildcards

No, but use GetFiles (which does) instead, and check the count of files returned

RE: File.Exists(), File.Delete() wildcards

(OP)
Already done it.
You answered faster than I was able to finish editing the original post.

How about Delete(sPath & "*.*")? Is in .NET anything that does it? (I couldn't find it so far...)

TIA!

Regards,

Ilya

RE: File.Exists(), File.Delete() wildcards

Just enumerate the result of getfiles, deleting each item as you go

RE: File.Exists(), File.Delete() wildcards

(OP)
IOW, roll-er-own...
OK, CAN-DO.
Thank you!

Regards,

Ilya

RE: File.Exists(), File.Delete() wildcards

Yep!

And, upon reflection, if it were me, I'd actually use system.io.DirectoryInfo.EnumerateFiles rather than GetFiles. It is more flexible, lighter-weight and faster. But it was only introduced in .Net 4.0, so GetFiles remains the generic solution

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close