Delete Multiple Files using *
I was trying to do something like this (that worked with the Kill method of VB6)
System.IO.File.Delete(OrderInfo.ParentFolderPath & "\NJ0*.DTA")
because there are several files that start with NJ0 and end with .DTA
for example
NJ025.DTA
NJ026.DTA
but there is no order to these numbers, so I need to clear them all out... and the above code returns an "illegal character in path" which is because of the "*"
so is there any way to do a multiple delete like this?
Re: Delete Multiple Files using *
found a solution using this
Code:
For Each FileFound As String In Directory.GetFiles(OrderInfo.ParentFolderPath, "NJ0*.DTA")
File.Delete(FileFound)
Next
Re: Delete Multiple Files using *
I believe wildcard deletes are in the next version of VB.NET.
Re: Delete Multiple Files using *
Quote:
Originally Posted by
kleinma
found a solution using this
Code:
For Each FileFound As String In Directory.GetFiles(OrderInfo.ParentFolderPath, "NJ0*.DTA")
File.Delete(FileFound)
Next
Cool. This works real well for wildcard deletes. I used *.tst and it deleted the four .tst files I created.
Re: Delete Multiple Files using *
how o u select the folder for the multiple deleytes to happen?
Re: Delete Multiple Files using *
Hi friends I could not run the method that kleinma mentioned but there another approach for this issue here is the code:
Code:
Module Module1
Sub Main()
Dim Pathname As String = "C:\Temp"
For Each FileFound As String In System.IO.Directory.GetFiles(Pathname).Where(Function(fi) System.IO.Path.GetFileName(fi) Like "K*").ToArray
Console.WriteLine(FileFound)
Next
Console.ReadKey()
End Sub
End Module
Regards
algea