Results 1 to 2 of 2

Thread: Using wildcards....

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Location
    London,UK
    Posts
    16

    Question Using wildcards....

    Ok, guys: Here's another one to ponder....

    I'm converting an old program which relied on the old FileListBox control in VB5. The program relied on the fact that I could stick wildcards in the FileListBox.Pattern property to list files matching a certain criteria so that I knew their full names for the program's processing routine.

    In VB.Net, the only way of getting a filedump of a directory that gives me filenames that I can reference to arithmetically is by using a ListBox control like this:

    -------------------------------------------------------------------------------
    Dim Directory = "c:\"
    Dim File As String
    Me.ListBox1.Items.Clear()
    Dim Files() As String = System.IO.Directory.GetFiles(directory)
    For Each file In files
    Me.ListBox1.Items.Add(file)
    Next
    -------------------------------------------------------------------------------

    Which would in the above case list all the files contained within "c:\".

    Now, before I start writing laborious code to validate each filename against the search criteria (which takes the form of a masked filename like "dw*.tiff" or "*.exe"). Is there an easy way of applying the filemask (or Pattern) to the above code and get VB.Net to do some work FOR me for a change??!?

    Darren.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    GetFiles has an overloaded version that accepts 2 parameters

    GetFiles(directory, searchpattern)


    searchpattern is a string, so try that

    GetFiles("c:\","*.exe")
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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