File operation with user-set wildcards

G

Guest

I want to delete files but I also want to set the wildcards manually. Look at
this example:

If TextBox1.Text = "" Then
Else
For Each foundFile As String In
My.Computer.FileSystem.GetFiles(curdir & "\_res_original", _
FileIO.SearchOption.SearchAllSubDirectories, TextBox1.Text)
My.Computer.FileSystem.DeleteFile(foundFile)
Next
End If

------------

TextBox1.Text should look like <"*.exe", "*.txt", "*.ini">
It works with one extension but if I specify many of them, vb gives an error
that there is an illegal character. I suppose it handles the commas not
correctly.

Thanks for any help
 
G

gene kelley

I want to delete files but I also want to set the wildcards manually. Look at
this example:

If TextBox1.Text = "" Then
Else
For Each foundFile As String In
My.Computer.FileSystem.GetFiles(curdir & "\_res_original", _
FileIO.SearchOption.SearchAllSubDirectories, TextBox1.Text)
My.Computer.FileSystem.DeleteFile(foundFile)
Next
End If

------------

TextBox1.Text should look like <"*.exe", "*.txt", "*.ini">
It works with one extension but if I specify many of them, vb gives an error
that there is an illegal character. I suppose it handles the commas not
correctly.

Thanks for any help


The argument for wildcard parameters is a string array:
Dim FileTypes As String() = {"*.exe", "*.txt", "*.ini"}

Change ....SearchAllSubDirectories, TextBox1.Text
to
.....SearchAllSubDirectories, FileTypes


Gene
 
G

Guest

Thanks.
But how can I convert the string from the textbox into a string array so it
will be recognized as separated wildcards?
 
P

Peter Proost

This returns a string array:

TextBox1.Text.split(","c)

hope this helps

Greetz, Peter
 
G

Guest

Alright, it works.
I forgot to write the c, that was the problem.
Thank you both for helping me!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top