0

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?

  • 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 Answers1

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