file size

vb6 Grenada
  • 14 years ago
    i  hav a problem
    that is i want to write a function that computes the size of files in a folder that is during first call to function it should compute the size of first 10 files in the folder(1-10) during next function call it should compute the sizes of next 10 files in that folder and so on untill all files are finished is it possible to accomplish this in VB that is i am passing one index to the function that is 1 means first 10,2 means
  • 14 years ago
    Hi Harish
     I Don't know why u need the size of files for 10 by 10. Ok leave it ur problem.

    The following code will solve ur problme. Actually this will give some new logics for u. U can change the code as per ur requirement.

    Private Sub Command1_Click()
        MsgBox fncFileSize(1, "C:\VB-Project\NewProcess\OldErrFiles") & " Bytes"
        MsgBox fncFileSize(2, "C:\VB-Project\NewProcess\OldErrFiles") & " Bytes"
        MsgBox fncFileSize(3, "C:\VB-Project\NewProcess\OldErrFiles") & " Bytes"
    End Sub
    Private Function fncFileSize(intParam As Integer, strFilePath As String) As Long
    On Error GoTo ErrFunc

        Dim fs, RAWFolder, File
        Dim intCount As Integer
        Dim lngFirst, lngSecond, lngElse As Long
       
        Set fs = CreateObject("Scripting.filesystemObject")
        Set RAWFolder = fs.GetFolder(strFilePath & "\" & gstrFileFolder)
       
        intCount = 0
        lngFirst = lngSecond = lngElse = 0
       
        If (Right(strFilePath, 1) = "\") Then
            strFilePath = Mid(strFilePath, 1, Len(strFilePath) - 1)
        End If
       
           
        For Each File In RAWFolder.Files
            intCount = intCount + 1
           
            Select Case intCount
                Case 1 To 10
                    lngFirst = lngFirst + FileLen(strFilePath & "\" & File.Name)
                    If (intCount = 10 And intParam = 1) Then Exit For
                Case 11 To 20
                    lngSecond = lngSecond + FileLen(strFilePath & "\" & File.Name)
                    If (intCount = 20 And intParam = 2) Then Exit For
                Case Else
                    lngElse = lngElse + FileLen(strFilePath & "\" & File.Name)
            End Select
        Next

        Select Case intParam
            Case 1
                fncFileSize = lngFirst
            Case 2
                fncFileSize = lngSecond
            Case Else
                fncFileSize = lngElse
        End Select
       
        Exit Function
       
    ErrFunc:
        fncFileSize = 0
    End Function

    Good Luck

    Regards
    Hari K


































































  • 14 years ago

    thank u hari i will try it

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Beware of bugs in the above code; I have only proved it correct, not tried it.” - Donald Knuth