[Webinar] Streamline your web hosting managementRegister Today

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

Selecting the appropriate "set"...

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

file1_0.dgp
file1_1.txt
file1_2.txt
file1_3.txt
file1_4.txt
file2_0.dgp
file2_1.txt
file2_2.txt
file2_3.txt
file2_4.txt

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.

Thanks!
0
vilusion
Asked:
vilusion
  • 2
1 Solution
 
Ramesh SrinivasTechnical ConsultantCommented:
Hi,

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

                FileArray.Clear()
                currFileGrp = oFile
                currFileGrpSze = 0

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

        Next

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

        For i As Integer = 0 To FileArray.Count - 1
            Console.WriteLine(FileArray.Item(i).ToString)
        Next i


regards,

KS
0
 
Ramesh SrinivasTechnical ConsultantCommented:
Replace the directory path with your own and test thoroughly :P
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

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