In How to parse a batch parameter, I introduced the %~z1 syntax for
determining the size of a file. I used this syntax in
How can I determine the size of a file in a CMD script? and
How can I determine the size and count of files in a folder from a command prompt or batch?
Some versions of CMD.EXE may not always properly return the file size. To workaround this behavior, I have scripted SizeFile.bat.
The syntax for using SizeFile.bat is:
call sizefile FileName size
Where FileName is the fully qualified path and file name of the file whose size you wish to determine, and size is a call directed numeric environment variable that will contain the size of the file.
SizeFile.bat contains:
@echo off if \{%2\}==\{\} @echo Syntax: SizeFile FileName Size&exit /b 1 if not exist %1 @echo SizeFile: %1 does NOT exist&exit /b 2 setlocal for /f "Tokens=3" %%a in ('dir %1 /A^|Findstr /i /c:"1 File(S)"') do ( set p3=%%a ) set p3=%p3:,=% endlocal&set/a %2=%p3% exit /b 0
0 comments
Hide comments