Windows command for file size only
Solution 1:
If you are inside a batch script, you can use argument variable tricks to get the filesize:
filesize.bat:
@echo off
echo %~z1
This gives results like the ones you suggest in your question.
Type
help call
at the command prompt for all of the crazy variable manipulation options. Also see this article for more information.
Edit: This only works in Windows 2000 and later
Solution 2:
If you don't want to do this in a batch script, you can do this from the command line like this:
for %I in (test.jpg) do @echo %~zI
Ugly, but it works. You can also pass in a file mask to get a listing for more than one file:
for %I in (*.doc) do @echo %~znI
Will display the size, file name of each .DOC file.
Solution 3:
Use a function to get rid off some limitation in the ~z
operator. It is especially useful with a for
loop:
@echo off
set size=0
call :filesize "C:\backup\20120714-0035\error.log"
echo file size is %size%
goto :eof
:: Set filesize of first argument in %size% variable, and return
:filesize
set size=%~z1
exit /b 0