Command for getting the file size

batch-file, filesize, windows-7

Solution

You don't need an extra batch file, you could move your filename into %1 with a call to a function or you can use a FOR loop.

call :getFilesize diff_out.txt
echo %fileSize%
exit /b

:getFilesize
set filesize=%~z1
exit /b

Or

for %%A in (diff_out.txt) do set fileSize=%%~zA

Problem

Could anybody please tell me a shell command for Windows 7 which would take a file path as argument and return the size of that file - Something like: ``` fileSize.cmd file.txt ``` ...which will give me `1KB`. One question in SO noted the command `echo %~z1`, but for this, I have to write a separate batch file and use this command in it. I was thinking of modifying my existing bat file and incorporate this command somehow. My batch file looks like this: ``` p4 diff //sources/j2cs/output.txt >> diff_out.txt ``` I have to add above command in the existing bat file to find the file size of `diff_out.txt`.

Original source