Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

GetFiles mask

Posted on 2007-11-19
5
Medium Priority
?
378 Views
Last Modified: 2008-02-01
This should be easy but I'm stumped.  I am doing a Directory.GetFiles and want to only find files beginning with GP, having a character for the third spot, and ending in 5 digits plus an extension of ".inh".  It must be exactly that.

So for example, a filename might be GPW12345.INH.

I'd want to not find files such as GPW12345ABCDEFG.INH and GPWABCDE.INH.

I'd think a mask such as "GP?#####.INH" would work but it does not.  I tried "GP??????.INH" and it returns files longer than 8+3 in length.

How can I do this?

Thanks,
Chris
0
Comment
Question by:chlade
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:Autoeforms
ID: 20313371
something like this should do the trick.
please note i did not compile and test this.
but the idea is to get your list of INH files and then
rip through the array building a new array for all the files
that match your criteria.

hope this helps
greg

        Dim sFileName As String
        Dim sFileNameWithPath As String
        Dim sNewList() As String
        Dim iX As Integer = 0
        Dim sCh As String
        For Each sFileNameWithPath In sFiles
            sFileNAme = System.IO.Path.GetFileNameWithoutExtension(sFileNameWithPath)
            sCh = Mid(sfilename, 3, 1).toupper
            If sFileName.length > 8 Then
            elseIf sCH < "A" orelse _  sch > "Z" Then
            ElseIf IsNumeric(Mid(sfilename, 4, 5)) = False Then
            Else
                ReDim Preserve sNewList(iX)
                sNewList(iX) = sfilename
                iX += 1
            End If
        Next

Open in new window

0
 

Author Comment

by:chlade
ID: 20313412
Ok.  I thought of doing that but was hoping there was a way to do it via a file mask so that I don't have to loop through all of them.

Is that possible or am I left with no option other than to loop through them?
0
 
LVL 8

Accepted Solution

by:
Autoeforms earned 1600 total points
ID: 20313452
none that i know of.
i would build it as a function call and have it return the result you want

g
0
 
LVL 27

Assisted Solution

by:VBRocks
VBRocks earned 400 total points
ID: 20313500
I think you are actually going to have to loop through them, but here's an example of how you can
search for a match using RegEx:

        Dim pattern As String = "GP[A-Z,a-z][0-9]{5}.INH"    'pattern to serach for
        Dim match As System.Text.RegularExpressions.Match

        Dim list As New List(Of IO.FileInfo)
        For Each fil As IO.FileInfo In _
            New IO.DirectoryInfo("C:\TEMP\Test").GetFiles("GP*.INH")

            match = System.Text.RegularExpressions.Regex.Match(fil.Name, pattern)

            If match.Success = True Then
                list.Add(fil)
            End If

        Next


        'View list:
        For Each item As IO.FileInfo In list
            Debug.WriteLine(item.Name)

        Next

0
 

Author Comment

by:chlade
ID: 20316835
Thanks for the help!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question