I want a script which check if the file size is less that 1KB. If it is yes, you have to print you can copy or else you show you can't copy. I'm new to scripting can anybody help me?
Asked
Active
Viewed 783 times
0
-
These topics already answered your question : [checking-file-size-in-a-batch-script](http://stackoverflow.com/questions/7881035/checking-file-size-in-a-batch-script) [how-can-i-check-the-size-of-a-file-in-a-windows-batch-script](http://stackoverflow.com/questions/1199645/how-can-i-check-the-size-of-a-file-in-a-windows-batch-script) – jirarium Feb 23 '17 at 06:42
1 Answers
0
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:
@echo off
setlocal
set file="test.cmd"
set maxbytesize=1000
FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA
if %size% LSS %maxbytesize% (
echo.File is ^< %maxbytesize% bytes
) ELSE (
echo.File is ^>= %maxbytesize% bytes
)

Ramkrushna
- 36
- 3
-
11. Why do you use `for /F`? a standard `for` loop is perfectly fine: `for %%A in ("%file%") do set "size=%%~zA"`. 2. This does not work for files of 2 GiB size or more. – aschipfl Feb 23 '17 at 12:52
-
-