need to count patterns in folder

need to count the following patterns in the folder:
 Msomething_Vsomethingelse , for example
 M0000123_V0000444_0001.pdf
 M0000123_V0000444_0002.pdf
 M0000123_V0000445_0001.pdf
 M0000124_V0000445_0001.pdf
 M0000124_V0000445_0007.pdf                                   should give me 3
 
AlexF777Asked:
Who is Participating?
 
PaulHewsCommented:
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("_"))
            Debug.WriteLine(FilePatt)
            If Not FilePatternHash.ContainsKey(FilePatt) Then
                FilePatternHash.Add(FilePatt, FilePatt)
                Count += 1
            End If
        Next
        MsgBox(Count)
    End Sub
End Class
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"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?

0
 
Fernando SotoRetiredCommented:
I don't get it either?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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

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

Bob
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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)
            Debug.Print(file)
        Next
    End Sub
0
 
AlexF777Author Commented:
outstanding
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.