need to count patterns in folder

Posted on 2007-08-06
Last Modified: 2013-11-05
need to count the following patterns in the folder:
 Msomething_Vsomethingelse , for example
 M0000124_V0000445_0007.pdf                                   should give me 3
Question by:AlexF777
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    "should give me 3"

    I don't get it...wouldn't the count be 5?

    Your pattern is "Msomething_Vsomethingelse", which all of them have.

    Can you explain which 3 are counted and why?...along with why the other two are NOT counted?

    LVL 62

    Expert Comment

    by:Fernando Soto
    I don't get it either?
    LVL 96

    Expert Comment

    by:Bob Learned
    Ok, you stumped the panel, but here's my guess:

    #1:  M0000123
    #2:  V0000444
    #3:  0001

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Are you looking for all .PDF files with specific "M" and "V" values?

    If so, something like this would work:

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim M As Integer = 124
            Dim V As Integer = 445
            Dim pattern As String = "M" & M.ToString.PadLeft(7, "0") & "_" & "V" & V.ToString.ToString.PadLeft(7, "0") & "*.pdf"
            For Each file As String In My.Computer.FileSystem.GetFiles("c:\", FileIO.SearchOption.SearchTopLevelOnly, pattern)
        End Sub
    LVL 38

    Accepted Solution

    Public Class Form1

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim Files() As String = System.IO.Directory.GetFiles("C:\temp", "*.pdf")
            Dim FilePatternHash As New Hashtable
            Dim Count As Integer
            For i As Integer = 0 To Files.GetUpperBound(0)
                Dim FilePatt As String = Files(i).Substring(Files(i).LastIndexOf("\"c) + 1)
                FilePatt = FilePatt.Substring(0, FilePatt.LastIndexOf("_"))
                If Not FilePatternHash.ContainsKey(FilePatt) Then
                    FilePatternHash.Add(FilePatt, FilePatt)
                    Count += 1
                End If
        End Sub
    End Class

    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    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…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now