Results 1 to 8 of 8

Thread: Directory Size

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    7

    Cool Directory Size

    Can you help me in determining the size of a Folder using VB 6

  2. #2

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    7
    I gave a try and the following code works

    here it is

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder("c:\shammy")
    MsgBox (f.Size())

  3. #3
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252
    Ok guys, I tried this today:

    VB Code:
    1. Private Sub cmdWindowsFolderSize_Click()
    2.     Dim objFSO As FileSystemObject
    3.     Dim objFolder As Folder
    4.    
    5.     Set objFSO = New FileSystemObject
    6.     Set objFolder = objFSO.GetFolder("C:\Windows")
    7.     MsgBox objFolder.Size
    8. End Sub

    And it gives "User-defined type not defined" and it highlights the objFSO As FileSystemObject bit.

    What I am missing here?

    Thanks your help.


    Edit: Thank you very much vbNeo and dis1411 (for project -> references, and check Microsoft Scripting Runtime).
    Last edited by ~*McoreD*~; Nov 20th, 2003 at 10:57 AM.

  4. #4
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Well

    try including the 'Microsoft Scripting Runtime' as a reference to you project.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  5. #5
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252

    Thank you!

    Thanks vbNeo for the help!

    One more thing: VB doesn't seem to understand the %SystemRoot% command.
    Any alternative for that guys?

    VB Code:
    1. 'Downloads
    2.     Set objFSO = New FileSystemObject
    3.     Set objFolder = objFSO.GetFolder("%SystemRoot%\Downloads")
    4.     dblDownloads = objFolder.Size
    5.     txtDownloads.Text = dblDownloads / 1048576

  6. #6
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252

    %SystemRoot% Alternative

    Any help for the above post guys?

    I know that:

    FS.GetSpecialFolder(0) - Gives Windows folder path
    fs.GetSpecialFolder(1) - Gives SystemFolder Path
    fs.GetSpecialFolder(2) - Gives Temp folder Path
    where Fs is the filesystemobject

    But, I want only C: (as in %SYSTEMROOT%, not C:\Windows.

    Thanks again.

  7. #7
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    try

    msgbox environ("SystemDrive")

  8. #8
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252
    Awesome! The following code worked like a charm.

    VB Code:
    1. 'Downloads
    2.     Set objFSO = New FileSystemObject
    3.     Set objFolder = objFSO.GetFolder(Environ("SystemDrive") & ("\Downloads"))
    4.     dblDownloads = objFolder.Size
    5.     txtDownloads.Text = FormatNumber((dblDownloads / 1048576), 2)

    You da MAN dude.

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