Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

DriveSpaceFree issue


  • Please log in to reply
3 replies to this topic
quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005
Some of us still have to use floppies and other storage devices that may have less than 1MB of free space on it.

The built-in function DriveSpaceFree rounds down to the nearest MB.

So a storage device like a floppy or a micro storage devices which my company uses may have 900K free on the device and therefore I can still use it.

Can DriveSpaceFree have an extra option added to it to make it not round down, but just return the exact amount?

Cheers. :-)
Stuart Halliday

Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
You could use GetDiskFreeSpaceEx:

Msgbox % GetDiskFreeSpace("A:") 
; DriveSpaceFree: 1, Explorer: 1.38 MB free, script: 1.389648 MB

GetDiskFreeSpace( lpDirectoryName )
{
	VarSetCapacity( lpFreeBytesAvailable,32 )
	
	DllCall("GetDiskFreeSpaceExA"
	, Str, lpDirectoryName, UInt, &lpFreeBytesAvailable, Uint,0, UInt,0 )
		
	Return % Numget( lpFreeBytesAvailable ) / ( 1024*1024 ) . " MB"
}

"Anything worth doing is worth doing slowly." - Mae West
Posted Image

quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005

You could use GetDiskFreeSpaceEx:

Msgbox % GetDiskFreeSpace("A:") 
; DriveSpaceFree: 1, Explorer: 1.38 MB free, script: 1.389648 MB

GetDiskFreeSpace( lpDirectoryName )
{
	VarSetCapacity( lpFreeBytesAvailable,32 )
	
	DllCall("GetDiskFreeSpaceExA"
	, Str, lpDirectoryName, UInt, &lpFreeBytesAvailable, Uint,0, UInt,0 )
		
	Return % Numget( lpFreeBytesAvailable ) / ( 1024*1024 ) . " MB"
}


Hmm nice solution Serenity.
I seem to be using 3rd party functions more and more these days instead of the built-in one. :D

I wonder who and when decides if a function needs to be built-in or via a library? I guess in theory very few actually do?

Thanks again for this bit of code.


<added>
Actually I've tried this code now.

It returns the right value for my floppy drive A:
But using it on my D: hard drive which has 8.39GB free it says it has 405.464844 MB free.

I don't think that's right!
:lol:
Stuart Halliday

Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
This should work:

Msgbox % GetDiskFreeSpace("C:")

GetDiskFreeSpace( lpDirectoryName )
{
	VarSetCapacity( lpFreeBytesAvailable,32 )
	
	DllCall("GetDiskFreeSpaceExA"
	, Str, lpDirectoryName, UInt, &lpFreeBytesAvailable, Uint,0, UInt,0 )
			
	Size := Numget( lpFreeBytesAvailable, 0, "Int64" )
	Return Size < 1073741824 ? Size / 1048576 . " MB" : Size / 1073741824 . " GB" 
}

I wonder who and when decides if a function needs to be built-in or via a library? I guess in theory very few actually do?


You could ask for it in the Wish List forum.
"Anything worth doing is worth doing slowly." - Mae West
Posted Image