Getting file size in KB using batch file

To get file size using batch file, we use variable with modifier. Then set /a, performs match operation (divide by 1024). Unlike other examples, this example works on any Windows language.

@echo off
:: Name: file_size.bat
:: Author
:: Calculate file size in KB from %1
set /a size = %~z1 / 1024
echo %size% KB

file_size.bat "c:\files\some_file.dat"

Quotes necessary when there are spaces in file or folder name.

Tested on Windows XP and Windows Server 2003.