Reputation: 4297
for %%a in (.\*.jpg) do @if %%~za gtr 245760 (
:WhileD
resize /overwrite /width:imagewidth-100 %%a %%~na.jpg
if %%~za gtr 245760 goto WhileD
)
The Code above should check all images in a folder and if it is greater than 240KB, it resizes it till its size becomes less than 240KB, and then process to the next file,
But it is not working :(
Upvotes: 2
Views: 95
Reputation: 11367
goto
commands break for loops. Use routines to contain goto
sub-loops.for %%a in (.\*.jpg) do @if %%~za gtr 245760 ( call :WhileD "%%~a" ) else echo add move command here.
exit /b 0
:WhileD <File>
resize /overwrite /width:imagewidth-100 %1 %~n1.jpg
if %~z1 gtr 245760 goto WhileD
exit /b 0
Upvotes: 2
Reputation: 80113
:WhileD
for %%a in (.\*.jpg) do if %%~za gtr 245760 (
resize /overwrite /width:imagewidth-100 %%a %%~na.jpg
goto WhileD
)
This should solve the problem.
Upvotes: 2
Reputation: 469
Try this
FOR %%A IN (*.jpg) DO CALL :CHECKFILE %%A %%~nA
EXIT /B 0
:CHECKFILE
FOR /F "usebackq" %%A IN ('%1') DO SET FSIZE=%%~zA
IF %FSIZE% LEQ 245760 EXIT /B 0
resize /overwrite /width:imagewidth-100 %1 %2.jpg
GOTO CHECKFILE
Upvotes: 1