|
-
Dec 15th, 2004, 02:38 PM
#1
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?
Last edited by kleinma; Dec 15th, 2004 at 02:48 PM.
-
Dec 15th, 2004, 02:47 PM
#2
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
-
Dec 15th, 2004, 10:42 PM
#3
Re: Delete Multiple Files using *
I believe wildcard deletes are in the next version of VB.NET.
-
Sep 22nd, 2009, 08:44 AM
#4
Addicted Member
Re: Delete Multiple Files using *
 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.
-
Jul 5th, 2016, 10:35 AM
#5
New Member
Re: Delete Multiple Files using *
how o u select the folder for the multiple deleytes to happen?
-
Jul 7th, 2016, 01:56 PM
#6
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|