Vb.Net - Delete an existing file using a "Wildcard"

Vb.Net - Delete an existing file using a "Wildcard"

isocam
Collaborator Collaborator
1,769 Views
1 Reply
Message 1 of 2

Vb.Net - Delete an existing file using a "Wildcard"

isocam
Collaborator
Collaborator

Can anybody help?

 

I am writing a Vb.Net "Addin" for Inventor.

 

I am trying to delete an existing file using a "Wildcard", but, I have tried various solutions but none seem to work!


For example:

Say I have a file called "Test123456.txt" and I want to delete it using the wildcard "Test*.txt" (* being the Wildcard).


Can anybody tell me how to do this?

 

Many thanks in advance!

 

Darren

0 Likes
Accepted solutions (1)
1,770 Views
1 Reply
Reply (1)
Message 2 of 2

Dev_rim
Advocate
Advocate
Accepted solution

Hi there.

You have to create a Directory Info object using the path of the folder that contains files you want to delete. And look for all files inside of it "Test*.text"

If you want to look for all sub folders, You can use this:

Dim dinfo As New DirectoryInfo(YOUR_FOLDER_PATH)
For Each myFile In dinfo.GetFiles("Test*.txt", SearchOption.AllDirectories)
    File.Delete(myFile)
Next 

If you want to check only the folder you entered, not the subfolders then you have to change "SearchOption.AllDirectories" to "SearchOption.TopDirectoryOnly".

 

I hope it will help.

 

Regards

Devrim

 

If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards
0 Likes