Results 1 to 14 of 14
  1. #1
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Getting the total size of a disk/directory in MB

    Those chaps/mschaps who do BATch file programming will know that the maximum size of an arithmetic variable is 2,147,483,647, which is 2 GB in anyone's money. So trying to process the final line from (say) DIR H: /S is not going to be a good move if the wretched user has a home directory more than 2 GB in size, because there is no option to get anything other than bytes from DIR.

    What i would like is a "free" and fast program which will give me the total size of a directory or (shared) drive in MB. I think we can ignore the odd kilobyte...

    DISKUSE from the Resource Kits is a) agonisingly slow, and [img]/forums/images/smilies/cool.gif[/img] gives the result in bytes. I've looked at a couple of other programs, but they either give far too much information or cost money.

    All bright ideas welcomed! Thanks!
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    Cincinnati, Ohio, USA
    Posts
    7,089
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the total size of a disk/directory in MB

    For my shareware dollars, nothing beats Treesize Pro.
    -Mark

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Getting the total size of a disk/directory in MB

    If you need only to process one at a time on an infrequent basis, File Explorer's Properties (right click the drive or Folder, select Properties) information gives you MB. You could also try NoNags and FileDudes for disk catalog utilities, and Treesize Pro also comes in an non-Pro (amateur?) freeware version.

    But a question ... here's the listing from my work userdrive using dir /s in Win 2000 (only system I have access to right now):

    Total Files Listed:
    12470 File(s) 2,933,130,564 bytes
    2981 Dir(s) 8,104,808,448 bytes free

    More than 2 GB of files are handled by Win 2000 Dir command. Which OS are you using?
    -John ... I float in liquid gardens
    UTC -7ąDS

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Getting the total size of a disk/directory in MB

    Hmmm, I see that same limitation with these properties of VBScript's FileSystemObject:

    Drive.TotalSize - returns a variant Long integer, maxes at 2,147,483,648 (bytes)
    Drive.FreeSpace - ditto
    Folder.Size - ditto

    Could you maybe use a Windows API call?

  5. #5
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Getting the total size of a disk/directory in MB

    Three responses:
    * Sorry, should have said I'm talking NT 4, where of course Windows NT Explorer gives the space used on the disk partition, niot on the shared drive itself.
    * And that we have a small number of copies of the excellent Treesize Professional for Administrators to use, but couldn't afford/justify putting it out to all staff.
    * DIR gives the total size of a file or directory, but in BYTES - my problem is processing the bytes value in a BATch file to give the total shared drive size in MB.

    If nobody can come up with a program which enumerates all the files in shared drive and totals the results in MB, I will have to do something devious with the final line output from
    DIR H: /S /W /-C
    in BATch, such as:
    * processing anything less than 2 GB by dividing by 1024*1024 (exact to the nearest MB)
    * if the bytes value is greater than 2 GB, extracting the left-most nine digits from the bytes value, and then determining what should be the appropriate divisor value to get an approximate result in MB.

    As an example of the last point, suppose the total size of the user's H: drive was 3,123,456,789 bytes, which is 2978.76 MB. Taking the first nine digits of the bytes value gives me 312345678, which if divided by 1024*102 (leaving the 4 off 1024) gives me 2990 MB. Depending on the number of digits omitted from the right-hand side, it should be straightforward to come up with a table of [number of digits omitted => matching divisor value] to give a fairly accurate answer, without even bothering to round up the nine-digits-value if the next digit is 5 or above.
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Getting the total size of a disk/directory in MB

    Okay, if you can get me the string 3,123,456,789 I can get you KB and MB by casting the string to a Double:
    <pre>Function MakeKB(strBytes As String) As String
    ' Calculate KB (no commas) from bytes (with or without commas)
    ' Requires VBA6 (Off2K+) or VBScript (in which case, remove the var typing)
    ' Eliminate commas
    strBytes = Replace(strBytes, ",", "")
    ' Convert to a double-precision number, divide by 1024, round up the old-fashioned way
    ' and reformat as a string return value
    MakeKB = FormatNumber(Int((CDbl(strBytes) / 1024) + 0.5), _
    0, vbTrue, vbFalse, vbFalse)
    End Function

    Sub TestMakeKB()
    MsgBox MakeKB("3,123,456,789") & " KB"
    MsgBox MakeKB(MakeKB("3,123,456,789")) & " MB"
    End Sub</pre>

    I think it checks out, but you should of course test...

  7. #7
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Getting the total size of a disk/directory in MB

    Jefferson: using DIR ... /-C I can guarantee you a string of n digits utterly free from commas!

    Pardon my quite breathtaking ignorance, but how could I use your VB function within a BATch file (which loads the required n-digit total-bytes-used value into the environment variable %bytes%)? And could you load the resulting MB value into an environment variable called %megabytes%, so I could display it on the console/put it in a file/etc?

    @echo off
    echo Determining the size of your H: drive...
    echo (for large H: drives, this may be a slow process)
    setlocal
    :: directory size given in bytes, fairly uselessly...
    for /f "tokens=1,3" %%a in ('dir /w /s /-c H: ^| findstr "File(s)"') do set files=%%a& set bytes=%%b
    echo %files% %bytes%
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  8. #8
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Getting the total size of a disk/directory in MB

    >* I'm talking NT 4, where of course Windows NT Explorer gives the space
    > used on the disk partition, not on the shared drive itself.

    Whoops, my error, Win 2000 does the same thing in File Explorer. (I -wish- I had that much space!)
    -John ... I float in liquid gardens
    UTC -7ąDS

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Getting the total size of a disk/directory in MB

    Well, hmmm. VBScript files can execute from the command line using CScript.exe.

    The Windows Script Host object model contains a WshShell object that can access an WshEnvironment properties collection. However, I don't know if this includes properties only within that little virtual host or the ones you are setting in the bigger world of your shell. In brief, some experimentation will be required to see if it is feasible to use a script and, if not, a little executable might have to be made.

    Well, you mention a file. VBScript can create and write to a file. (I've posted examples of using the TextStream object somewhere in the Lounge.) And even if it is unaware of the environment variables, it can be passed a parameters on the command line (see illustration).

    Are we getting closer?
    Attached Images Attached Images

  10. #10
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Getting the total size of a disk/directory in MB

    I've come across a utility which does calculations in floating point to about 20 digits precision, in Frank Westlake's CONSET. Takes a non-trivial amount of understanding of the documentation, but enables me to write my BATch file as:

    @echo off
    echo Determining the size of the H: drive...
    echo (for large H: drives, this may be a slow process)
    setlocal
    :: directory size given in bytes, fairly uselessly...
    set forcmds=dir /w /s /-c H: ^^^| findstr "File(s)"
    for /f "tokens=3" %%a in ('%forcmds%') do set bytes=%%a
    :: CONSET utility by Frank Westlake
    conset /a "mb=round((%bytes%/1048576),0)"
    echo H Drive size is %mb% MB, or %bytes% bytes
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  11. #11
    New Lounger
    Join Date
    Jan 2003
    Location
    San Jose, California, USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the total size of a disk/directory in

    Edited by WyllyWylly to add URL code. See the Quick Guide.[/i] <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    There is an awesome, small program that you can run, called TREEINFO.
    You can download it here: http://www.gammon.com.au/utilities/utilities.htm

    Or get the file here, directly......
    Attached Files Attached Files

  12. #12
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Getting the total size of a disk/directory in

    That's almost exactly what I was after - thank you very much! John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  13. #13
    New Lounger
    Join Date
    Jan 2003
    Location
    San Jose, California, USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting the total size of a disk/directory in

    There is one other program that you may be interested in. It is called TreeSize Professional.
    (I have tried a whole mess of utiliites trying to get one that will give me the total of directoris AND subdirectories.)
    Treeinfo and this one are the only two that I found useful.
    This utility uses a GUI, whereas TREEINFO is DOS based.

    You can download TreeSize Professional here:
    http://www.jam-software.com/treesize.shtml

  14. #14
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Getting the total size of a disk/directory in

    Sorry, but I already mentioned TreeSize Professional (now in 3.00 alpha 10, BTW, if you're a beta tester [huh??]) in my second post about four from the top! As I said there, it costs too much to put out to 2500 staff.

    In passing, it would be nice for Microsoft to have developed a File System that didn't require you to enumerate every file in every directory to work out how much space a network share was using! When I run TreeSize Pro on our SAN, it takes <font color=blue>several hours</font color=blue> to do the whole thing ... and that's with less than 600 GB of space!
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

Posting Permissions

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