Sign in to follow this  
Followers 0
monoceres

_DriveGetClusterSize

5 posts in this topic

#1 ·  Posted (edited)

Hi!

Needed this for a project of mine and I thought that someone else might need it.

UDF:

; #FUNCTION#;===============================================================================
;
; Name...........: _DriveGetClusterSize
; Description ...: Returns the cluster size of a drive
; Syntax.........: _DriveGetClusterSize([$sDrive=@HomeDrive])
; Parameters ....:
; Return values .: Success - Cluster size in bytes
;               .; Failure - -1 and @error=1
; Author ........: Andreas Karlsson (monoceres)
; Modified.......:
; Remarks .......:
; Related .......: 
; Link ..........;
; Example .......; No
;
;;==========================================================================================
Func _DriveGetClusterSize($sDrive = @HomeDrive)
    If StringRight($sDrive,1)<>'\' Then $sDrive&='\'
    Local $iClusterSize, $vNULL, $aArray
    $aArray = DllCall("Kernel32.dll", "int", "GetDiskFreeSpace", "str", $sDrive, "dword*", $vNULL, "dword*", $vNULL, "dword*", $vNULL, "dword*", $vNULL)
    If IsArray($aArray) Then
        $iClusterSize = $aArray[2] * $aArray[3]
        Return SetError(0,0,$iClusterSize)
    EndIf
    Return SetError(1,0,-1)
EndFunc;==>_GetClusterSize

Example:

$file=FileOpenDialog("Select file","","All files (*.*)")

$size=FileGetSize($file)
$clustersize=_DriveGetClusterSize(StringLeft($file,3))
$sizeondisc=Ceiling($size/$clustersize)*$clustersize
MsgBox(0,"Info","Filename: "&$file&@CRLF&"Filesize: "&$size&" bytes"&@CRLF&"Size on disc: "&$sizeondisc&" bytes"&@CRLF&"Wasted: "&$sizeondisc-$size&" bytes")

:)

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites



Nice funtion, thanks for sharing.. :)

Share this post


Link to post
Share on other sites

Nice Job!

Oh.. I think you forgot something :)

$aArray = DllCall("Kernel32.dll", "int", "GetDiskFreeSpace", "str", $sDrive, "dword*", $vNULL, "dword*", $vNULL, "dword*", $vNULL, "dword*", $vNULL)


Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet()

Share this post


Link to post
Share on other sites

Thanks monoceres! :)


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Oh.. I think you forgot something :P

:)

Thanks for noticing :P


Broken link? PM me and I'll send you the file!

Share this post


Link to post
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
Sign in to follow this  
Followers 0