locked
Select files with wild card

    Question

  • I have tried this

    Code Snippet

    "C:\Users\Wayne\AppData\Roaming\Microsoft\Windows\Cookies\onlinestores.metaservices.microsoft*.txt"

     

     

    but returns an error.

    Code Snippet
    Second path fragment must not be a drive or UNC name. Parameter name: path2

     

     

    My code:

    Code Snippet

    Private Sub DeleteCookie(ByVal cookie As String)

        Dim s As String = Front & cookie & "*.txt"

        di.Refresh()

        Dim fi As FileInfo() = di.GetFiles(s)

        For Each File As FileInfo In fi

            If File.Name.Contains(cookie) Then

                MessageBox.Show(File.Name)

                'File.Delete()

            End If

        Next

    End Sub

     

     

    I want to catch things like name[1] and name[2]. I would appreciate any help.
    Sunday, July 20, 2008 7:39 PM

Answers

  • Actually your first statement was almost correct for example you can use this to get all files with cookie as part of the file name .

     

    Dim s As List(Of String) = New List(Of String) _

    (My.Computer.FileSystem.GetFiles("c:\", FileIO.SearchOption.SearchTopLevelOnly, "*" & cookie & "*.*"))

     

    Monday, July 21, 2008 11:22 AM

All replies

  • Here is some syntax to play around with:

    Dim s As List(Of String) = New List(Of String)(My.Computer.FileSystem.GetFiles("c:\", FileIO.SearchOption.SearchTopLevelOnly, New String() {"*.jpg", "*.bmp"}))

     

    It's a one liner, so fix the forum's wordwrap.

    Monday, July 21, 2008 1:03 AM
  • Thanks TallDude,

    I tried it....

     

    Code Snippet

     

    Dim s As List(Of String) = New List(Of String)(My.Computer.FileSystem.GetFiles(Front, FileIO.SearchOption.SearchTopLevelOnly, Cookie & "*.txt"))

     

     

    returns no files.

     

    Code Snippet

    Dim s As List(Of String) = New List(Of String)(My.Computer.FileSystem.GetFiles(Front, FileIO.SearchOption.SearchTopLevelOnly,"*.txt"))

     

     

    returns 250 files. I just want all files that match "google*.txt" which is 3 ---  "google[1].txt", "google[2].txt" and google[3].txt"

     


     

    Monday, July 21, 2008 8:47 AM
  • TallDude,

    Sorry about that. It did work. Stupid mistake on my part. Here is the code I ended up with.

    Code Snippet

    Dim ss As String = Front & "wayne@" & cookie

    Dim s As List(Of String) = New List(Of String)(My.Computer.FileSystem.GetFiles(Front, FileIO.SearchOption.SearchTopLevelOnly, New String() {"wayne@" & cookie & "*.txt"}))

    For Each str As String In s

        MessageBox.Show(str)

    Next

     

     

    I had forgot to add "wayne@".

    The origional using fileinfo does not work with wild cards. Wish it did.

    Thanks so much.

     

    Monday, July 21, 2008 9:52 AM
  • Actually your first statement was almost correct for example you can use this to get all files with cookie as part of the file name .

     

    Dim s As List(Of String) = New List(Of String) _

    (My.Computer.FileSystem.GetFiles("c:\", FileIO.SearchOption.SearchTopLevelOnly, "*" & cookie & "*.*"))

     

    Monday, July 21, 2008 11:22 AM