AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DriveSpaceFree issue

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
quatermass



Joined: 14 Dec 2005
Posts: 136

PostPosted: Fri Sep 19, 2008 10:39 am    Post subject: DriveSpaceFree issue Reply with quote

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. Smile
_________________
Stuart Halliday
Back to top
View user's profile Send private message
Serenity



Joined: 07 Nov 2004
Posts: 1276

PostPosted: Fri Sep 19, 2008 11:57 am    Post subject: Reply with quote

You could use GetDiskFreeSpaceEx:

Code:
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
Back to top
View user's profile Send private message Visit poster's website
quatermass



Joined: 14 Dec 2005
Posts: 136

PostPosted: Fri Sep 19, 2008 1:04 pm    Post subject: Reply with quote

Serenity wrote:
You could use GetDiskFreeSpaceEx:

Code:
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. Very Happy

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!
Laughing
_________________
Stuart Halliday
Back to top
View user's profile Send private message
Serenity



Joined: 07 Nov 2004
Posts: 1276

PostPosted: Fri Sep 19, 2008 3:16 pm    Post subject: Reply with quote

This should work:

Code:
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"
}


quatermass wrote:
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
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group