Jump to content

_DriveGetClusterSize


monoceres
 Share

Recommended Posts

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!

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...