omikron48 Posted August 15, 2009 Posted August 15, 2009 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)
nekkutta Posted August 15, 2009 Posted August 15, 2009 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]
omikron48 Posted August 16, 2009 Author Posted August 16, 2009 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.
Authenticity Posted August 16, 2009 Posted August 16, 2009 #include <String.au3> Global $oWMI = ObjGet('winmgmts:\\.\root\CIMV2') Global $oDrives = $oWMI.ExecQuery('SELECT * FROM Win32_LogicalDisk WHERE DeviceID="' & @HomeDrive & '"') For $oDrive In $oDrives ConsoleWrite(_StringAddThousandsSep($oDrive.FreeSpace) & ' bytes.' & @CRLF) Next
Yashied Posted August 16, 2009 Posted August 16, 2009 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) My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now