Jump to content

Getting better results?


Recommended Posts

I've been using this script for a long time now, but I'm finding that it's not all that good for the larger drives.

When I'm talking megabytes, the script works fine. But how can it be fixed to switch how it displays between megabytes when under 1 gig and showing fractions of a gigabyte when above, without converting gigabytes to megabytes?

;------ Change target drive(s) to scan here, only: -----------------------
$DriveToScan = @ScriptDir
;-------------------------------------------------------------------------


$var1 = DriveSpaceFree($DriveToScan)
$var2 = DriveSpaceTotal($DriveToScan)
;------------------------------------
$FreeSpace  = $var1
$TotalSpace = $var2
;------------------------------------
$FreeSpaceRoundedDown  = Floor($var1)
$TotalSpaceRoundedDown = Floor($var2)


MsgBox(262208,'"Free space on the "' & $DriveToScan & '" drive ...   ','The free space on the "' & $DriveToScan & _
            '" drive is:          ' & @CRLF & '-----------------------------------------------     ' & @CRLF & @CRLF & _
            $FreeSpace & ' MB, exactly' & @CRLF & @CRLF & _
            'or, ' & $FreeSpaceRoundedDown & ' MB, rounded down.' & @CRLF & @CRLF & @CRLF & _
            '(Or:  ' & $FreeSpaceRoundedDown & ' MB free out of ' & $TotalSpaceRoundedDown & ' MB, rounded down.)               ')

The above gives this result for my desktop:

The free space on the " ... \Desktop" drive is:
-----------------------------------------------

57352.7109375 MB, exactly

or, 57352 MB, rounded down.

(Or:  57352 MB out of 104333 MB, rounded down.)

where it would be nicer to have this type of output instead:

The free space on the " ... \Desktop" drive is:
-----------------------------------------------

57.3527109375 GB, exactly

or, 57 GB, rounded down.

(Or:  57 GB/101 GB free, rounded down.)

But on those drives where I'm talking MB vs GB, how to get the same script to display in this same type of manner showing MB in the units of measure instead?

Thanks!

Link to comment
Share on other sites

Hi Diana,

Just use sth. like:

If $var1 > 1024 Then
    $FreeSpace  = $var1 / 1024
    $TotalSpace = $var2 / 1024
    $unit = "GB"
Else
    $FreeSpace  = $var1
    $TotalSpace = $var2
    $unit = "MB"
EndIf

Now you have MB or GB depending on the size. Use the $unit variable in your text instead of hard-writing MB or GB.

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...