batch-fileoptimizationjpegjpegtran

Using Batch files to execute multiple commands


I'm using jpegtran to transform jpegs in a directory to an optimized version of itself. I do this for maybe 10-15 jpegs. I already wrote a batch file that executes all the commands for every jpeg, but I was wondering if there was an approach similar to a bash script where I can say:

jpegtran -optimize -copy none *.jpg optsameasoriginalfilename.jpg

Problem is, the target file cannot be the same as the file that is being converted unless it's going to a different directory.

Is there a batch file that can do this for me? Rather than me going in the batch file I made and manually changing all the names of the source and target filenames?

Thanks!


Solution

  • Alex K.'s answer:

    FOR %%f IN (*.JPG) DO jpegtran -optimize -copy %%f new_%%f
    

    Worked perfectly. This line of code also ran the last command twice, resulting in two files of the last jpeg, but that was a matter of a simple delete and still suits my needs.