简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM