Jump to content

Determining Free Space


Recommended Posts

Hello again.

I'm trying to make a new script now.

How do I go about determining my drive's free space in bytes?

DriveSpaceFree only returns free space in MBs with a float. Is it reliably accurate when you use that return value and just multiply it to 2^20? I did a few tests and it seems ok but I'm just worrying if it's not perfect all the time.

Global Const $drive = StringLeft(@ScriptDir, 3)
Global $free = DriveSpaceFree($drive) * 1024 * 1024
MsgBox(0, "Drive Free Space For " & $drive, $free)
Link to comment
Share on other sites

well, that's how I do it, and just to be sure I usually subtract about 25 to the DriveSpaceFree() before the *1024*1024 ie. "(DriveSpaceFree() - 25) * 1024 * 1024" but that is mainly when I am copying to a usb flash drive just to make sure that I don't overload the thing >_

[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Link to comment
Share on other sites

There are times when my $free calculation is different from the actual number when I view it in my flash drive's properties.

In any case, I just modified my algorithm to not rely on finding out the actual free space of my drive. It now works like a charm.

I was trying to make a dummy file generator that will populate my flash drive so viruses can't copy into it when I plug it into infected computers.

Link to comment
Share on other sites

Try this.

$tData = DllStructCreate('int64')
DllCall('kernel32.dll', 'int', 'GetDiskFreeSpaceEx', 'str', @HomeDrive, 'ptr', DllStructGetPtr($tData), 'ptr', 0, 'ptr', 0)
ConsoleWrite('Free space on ' & @HomeDrive & ' => ' & DllStructGetData($tData, 1) & ' bytes' & @CR)
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...