Selecting the appropriate "set"...

This may be a difficult question to explain, but here it goes.
Using the example below.


Let's say that the file1_1.txt thru file1_4.txt are 10meg a piece.  The file2_1.txt thru file2_4.txt are only 5meg a piece.  All these files are in the same folder.

What code could be used that when a command button was clicked VB would scan the .txt files for the largest file size "sets" (e.g. file1_1 thru file1_4) and then return the appropriate set files (e.g file1_1.txt, file1_2.txt, file1_3.txt, file1_4.txt) associated with that particular "set" to a checked listbox?

I tried to explain the best I could.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ramesh SrinivasTechnical ConsultantCommented:

It should just be a matter of going thru files in the directory and storing the group sizes and then comparing them to new group sizes each time you come across another starting point (i.e. a dgp file).

Assuming that the files are ordered as you showed me, something like the follow would give you the filenames of the files with the highest size total.

Dim oFile As String
        Dim FileArray As ArrayList = New ArrayList
        Dim currFileGrp As String
        Dim prevFileGrp As String
        Dim currFileGrpSze As Integer
        Dim prevFileGrpSze As Integer

        For Each oFile In Directory.GetFiles("c:\temp")

            If Microsoft.VisualBasic.Right(oFile, 3) = "dgp" Then

                If currFileGrpSze > prevFileGrpSze Then
                    prevFileGrpSze = currFileGrpSze
                    prevFileGrp = currFileGrp
                End If

                currFileGrp = oFile
                currFileGrpSze = 0

                Dim oFileInfo As FileInfo = New FileInfo(oFile)
                currFileGrpSze += oFileInfo.Length
            End If


        If currFileGrpSze > prevFileGrpSze Then
            prevFileGrpSze = currFileGrpSze
            prevFileGrp = currFileGrp
        End If

        For i As Integer = 0 To FileArray.Count - 1
        Next i



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ramesh SrinivasTechnical ConsultantCommented:
Replace the directory path with your own and test thoroughly :P
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.