I want to have a batch file which checks what the filesize
is of a file.
If it is bigger than %somany% kbytes,
it should redirect with GOTO to somewhere else.
Example:
[check for filesize]
IF %file% [filesize thing Bigger than] GOTO No
echo Great! Your filesize is smaller than %somany% kbytes.
pause
exit
:no
echo Um... You have a big filesize.
pause
exit
Another example
This was my solution for evaluating file sizes without using VB/perl/etc. and sticking with native windows shell commands:
Not the cleanest solution, but it gets the job done.
Just saw this old question looking to see if Windows had something built in. The ~z thing is something I didn't know about, but not applicable for me. I ended up with a Perl one-liner:
After a few "try and test" iterations I've found a way (still not present here) to get size of file in cycle variable (not a command line parameter):
If the file name is used as a parameter to the batch file, all you need is
%~z1
(1 means first parameter)If the file name is not a parameter, you can do something like:
If your
%file%
is an input parameter, you may use%~zN
, whereN
is the number of the parameter.E.g. a
test.bat
containingWill display the size of the first parameter, so if you use "
test myFile.txt
" it will display the size of the corresponding file.