FileGetSize()

Auto Hotkey

FileGetSize

Retrieves the size of a file.

OutputVar := FileGetSize(Filename, Units)
Function Example: FileTime := FileGetSize(A_AhkExe)

Parameters

OutputVar

The name of the variable in which to store the retrieved size (rounded down to the nearest whole number).

Filename

The name of the target file, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified. If omitted, the current file of the innermost enclosing File-Loop will be used instead.

Units

If present, this parameter causes the result to be returned in units other than bytes:
K = kilobytes
M = megabytes

ErrorLevel

ErrorLevel is set to 1 if there was a problem or 0 otherwise.

A_LastError is set to the result of the operating system's GetLastError() function.

Remarks

Files of any size are supported, even those over 4 gigabytes, and even if Units is bytes.

If the target file is a directory, the size will be reported as whatever the OS believes it to be (probably zero in all cases).

To calculate the size of folder, including all its files, follow this example:

FolderSize := 0
DirSelect, WhichFolder  ; Ask the user to pick a folder.
Loop, Files, %WhichFolder%\*.*, R
    FolderSize += A_LoopFileSize
MsgBox Size of %WhichFolder% is %FolderSize% bytes.

Related

FileGetAttrib, FileSetAttrib, FileGetTime, FileSetTime, FileGetVersion, File-loop

Example

FileGetSize, OutputVar, C:\My Documents\test.doc  ; Retrieve the size in bytes.
FileGetSize, OutputVar, C:\My Documents\test.doc, K  ; Retrieve the size in Kbytes.