FileGetSize

Retrieves the size of a file.

FileGetSize, OutputVar , Filename, Units

Parameters

OutputVar

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

Filename

If blank or omitted, the current file of the innermost enclosing file loop will be used. Otherwise, specify the name of the target file, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified.

Units

If blank or omitted, it defaults to B. Otherwise, specify one of the following letters to cause the result to be returned in specific units:

Error Handling

[v1.1.04+]: This command is able to throw an exception on failure. For more information, see Runtime Errors.

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:

SetBatchLines, -1  ; Make the operation run at maximum speed.
FolderSize := 0
FileSelectFolder, WhichFolder  ; Ask the user to pick a folder.
Loop, %WhichFolder%\*.*, , 1
    FolderSize += A_LoopFileSize
MsgBox Size of %WhichFolder% is %FolderSize% bytes.

FileGetAttrib, FileSetAttrib, FileGetTime, FileSetTime, FileGetVersion, file loop

Examples

Retrieves the size in bytes and stores it in OutputVar.

FileGetSize, OutputVar, C:\My Documents\test.doc

Retrieves the size in kilobytes and stores it in OutputVar.

FileGetSize, OutputVar, C:\My Documents\test.doc, K