How to see the total size of all files in a directory?

Hi all,


I'm a newbie at VB and I would like to know how to read the size of all files in a dir (*.txt or something) and after that showing the total size (in MB's) in a textbox.


Please help me!


E-mail would be appreciated!


Comments

  • : Hi all,


    : I'm a newbie at VB and I would like to know how to read the size of all files in a dir (*.txt or something) and after that showing the total size (in MB's) in a textbox.


    : Please help me!


    : E-mail would be appreciated!


    Function BytesInDir(ByVal DirName As String) As Long

    'Source:http://home.ici.net/~dmonroe/planetvb/code/usedbytes.htm

    Dim Filename As String

    Dim FileSize As Currency

    ' add a backslash if missing

    If Right$(DirName, 1) <> "" Then

    DirName = DirName & ""

    End If

    FileSize = 0

    Filename = Dir$(DirName & "*.*")

    Do While Filename <> ""

    FileSize = FileSize + FileLen(DirName & Filename)

    Filename = Dir$

    Loop

    BytesInDir = FileSize

    End Function


    Private Sub Command1_Click()

    'MsgBox BytesInDir("C:")

    'MsgBox BytesInDir("C:Windows")

    Text1 = ""

    Text1 = BytesInDir("C:Windows")

    End Sub




  • : : Hi all,


    : : I'm a newbie at VB and I would like to know how to read the size of all files in a dir (*.txt or something) and after that showing the total size (in MB's) in a textbox.


    : : Please help me!


    : : E-mail would be appreciated!


    : Function BytesInDir(ByVal DirName As String) As Long

    : 'Source:http://home.ici.net/~dmonroe/planetvb/code/usedbytes.htm

    : Dim Filename As String

    : Dim FileSize As Currency

    : ' add a backslash if missing

    : If Right$(DirName, 1) <> "" Then

    : DirName = DirName & ""

    : End If

    : FileSize = 0

    : Filename = Dir$(DirName & "*.*")

    : Do While Filename <> ""

    : FileSize = FileSize + FileLen(DirName & Filename)

    : Filename = Dir$

    : Loop

    : BytesInDir = FileSize

    : End Function


    : Private Sub Command1_Click()

    : 'MsgBox BytesInDir("C:")

    : 'MsgBox BytesInDir("C:Windows")

    : Text1 = ""

    : Text1 = BytesInDir("C:Windows")

    : End Sub





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories