Results 1 to 4 of 4

Thread: directories size!

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Location
    Saudi Arabia
    Posts
    2

    directories size!

    Hi there,

    I'm new in the programming world, i was thinking if i can in VB create a module (as dialog box) which allows me to print (to a txt file) a list of all the sub-directories of a directoty with its size in MB!.. if not what's the programming language which allow me to do this, I mean to interact with the MS windows platform in a direct manner!

    Tanx pals,
    alk1000

  2. #2
    Fanatic Member pradeepkrao's Avatar
    Join Date
    Sep 2001
    Location
    New Jersey
    Posts
    534

    Hi

    Do you need vb for this.. why dont you write a small batch file.. The code would be something like this..

    dir /p >> file.txt

    does this answer you..
    Learn by others experience as you cannot live long to experience them all.
    www.freewebs.com/pradeepkrao

    LOOK AT MY GAMES AT MY WEB SITE.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Private Const MAX_PATH = 260
    2.  
    3. Private Type FILETIME
    4.     dwLowDateTime As Long
    5.     dwHighDateTime As Long
    6. End Type
    7. Private Type WIN32_FIND_DATA
    8.     dwFileAttributes As Long
    9.     ftCreationTime As FILETIME
    10.     ftLastAccessTime As FILETIME
    11.     ftLastWriteTime As FILETIME
    12.     nFileSizeHigh As Long
    13.     nFileSizeLow As Long
    14.     dwReserved0 As Long
    15.     dwReserved1 As Long
    16.     cFileName As String * MAX_PATH
    17.     cAlternate As String * 14
    18. End Type
    19.  
    20. Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
    21. Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
    22. Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
    23.  
    24. Private Function EndSlash(ByVal PathIn As String) As String
    25. If Right$(PathIn, 1) = "\" Then
    26.     EndSlash = PathIn
    27. Else
    28.     EndSlash = PathIn & "\"
    29. End If
    30. End Function
    31.  
    32. Private Function SizeOf(ByVal DirPath As String) As Double
    33. Dim hFind As Long
    34. Dim fdata As WIN32_FIND_DATA
    35. Dim dblSize As Double
    36. Dim sName As String
    37. Dim x As Long
    38. On Error Resume Next
    39. x = GetAttr(DirPath)
    40. If Err Then SizeOf = 0: Exit Function
    41.  
    42. If (x And vbDirectory) = vbDirectory Then
    43.     dblSize = 0
    44.     Err.Clear
    45.     sName = Dir$(EndSlash(DirPath) & "*.*", vbSystem Or vbHidden Or vbDirectory)
    46.         If Err.Number = 0 Then
    47.            hFind = FindFirstFile(EndSlash(DirPath) & "*.*", fdata)
    48.                If hFind = 0 Then Exit Function
    49.                 Do
    50.                   If (fdata.dwFileAttributes And vbDirectory) = vbDirectory Then
    51.                     sName = Left$(fdata.cFileName, InStr(fdata.cFileName, vbNullChar) - 1)
    52.                        If sName <> "." And sName <> ".." Then
    53.                         dblSize = dblSize + SizeOf(EndSlash(DirPath) & sName)
    54.                        End If
    55.                   Else
    56.                     dblSize = dblSize + fdata.nFileSizeHigh * 65536 + fdata.nFileSizeLow
    57.                   End If
    58.                 DoEvents
    59.                 Loop While FindNextFile(hFind, fdata) <> 0
    60.                 hFind = FindClose(hFind)
    61.         End If
    62. Else
    63.     On Error Resume Next
    64.     dblSize = FileLen(DirPath)
    65. End If
    66. SizeOf = dblSize
    67. End Function
    68.  
    69. Private Sub Command1_Click()
    70. 'Replace 'c:\windows' with the directory name that you want to get its size.
    71. Screen.MousePointer = vbHourglass
    72. MsgBox SizeOf("c:\windows")
    73. Screen.MousePointer = vbDefault
    74. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Location
    Saudi Arabia
    Posts
    2

    Thumbs up

    HIagain,

    Just to tell that pradeepkrao did a great job. he emailed me a perfect solution. I thought to share it with everyone; u can have a closer look on the attachment.

    cheers, and tanx again for him
    Camille
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width