Search code examples
windowsbatch-fileimage-processingcommand-linejpegtran

How to Set Up & Use Jpegtran with Windows


I am a Windows user trying to get started with jpegtran and have not found a way to actually access the program. All questions I've found start at the command line, but when trying to duplicate the commands, I receive errors such as the following:

After viewing this question:

I tried to run these commands:

@echo none 
for /f "delims=" %%a in ('dir "*.jpg" /b /s /a-d') do (
echo processing "%%a"
"C:\Program Files\Image Optimization\jpegtran.exe" -optimize -progressive -copy none "%%a" "%%a.tmp"
move /Y "%%a.tmp" "%%a" >nul
)
pause

I get the error "%%a was not expected at this time."

My question is how to set up the folder structure for the images, jpegtran.exe file and the command prompt so that this command will run?


Solution

  • Your solution above looks to have correct format - but it is a batch file and you cannot paste it into a command prompt. Save the code in a text file, call it runjpg.bat and launch it in a folder with some jpg files to test. (Avoid calling the batchfile the same name as a command)