[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

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
 
0
AlexF777
Asked:
AlexF777
1 Solution
 
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 SotoCommented:
I don't get it either?
0
 
Bob LearnedCommented:
Ok, you stumped the panel, but here's my guess:

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

Bob
0
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!

 
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
 
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
 
AlexF777Author Commented:
outstanding
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now