Results 1 to 6 of 6

Thread: Delete Multiple Files using *

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Resolved 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.

  2. #2

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Delete Multiple Files using *

    I believe wildcard deletes are in the next version of VB.NET.

  4. #4
    Addicted Member rkeslar's Avatar
    Join Date
    Jul 2009
    Location
    Pittsburgh, PA
    Posts
    145

    Thumbs up Re: Delete Multiple Files using *

    Quote Originally Posted by kleinma View Post
    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.

  5. #5
    New Member
    Join Date
    Jul 2016
    Posts
    1

    Re: Delete Multiple Files using *

    how o u select the folder for the multiple deleytes to happen?

  6. #6
    Addicted Member
    Join Date
    Mar 2010
    Posts
    228

    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
  •  



Click Here to Expand Forum to Full Width