0

This command works for me:

To run from cmd.exe:
convert *.jpg -set filename:f "%t.%e" "%[filename:f].png"

The same, to run from bat-file (double % instead of single):
convert *.jpg -set filename:f "%%t.%%e" "%%[filename:f].png"

Now, let's assume I have this file hierarchy:

test\
 |-- small\               <-- this is an empty folder
 |-- image1.jpg
 |-- image2.jpg

How I should modify existing script to output files in small folder, as shown below?

Current behaviour:
test\
 |-- small\
 |-- image1.jpg
 |-- image2.jpg
 |-- image1.jpg.png
 |-- image2.jpg.png

Desired behaviour:
test\
 |-- small\
      |-- image1.jpg.png
      |-- image2.jpg.png
 |-- image1.jpg
 |-- image2.jpg

I tried to use %~dp0, but with no luck currently.

john c. j.
  • 490
  • 1
  • 20
  • 59

1 Answers1

1

I think I understand, but make a backup before trying:

mogrify -path small -format png *.jpg

I don't have Windows readily available to test, but in the light of your comments try:

convert *.jpg -set filename:f "%%t.%%e" "small/%%[filename:f].png"
Mark Setchell
  • 146,975
  • 21
  • 182
  • 306
  • Mark, thank you. Currently I'm trying to use `convert` instead of `mogrify` to avoid filename collisions, as described here: https://stackoverflow.com/questions/44284542/convert-images-which-have-the-same-names-but-different-extensions – john c. j. Dec 22 '17 at 12:08
  • I have updated my answer, please have another look. You may need a backslash on Windows, or a caret (`^`) before the slash. – Mark Setchell Dec 22 '17 at 12:15
  • Not sure how you could have filename collisions actually, since all your files come from the same directory so they must already be unique. – Mark Setchell Dec 22 '17 at 12:21
  • Yes, backslash, but doesn't work. I tried similar ways early, with no luck – john c. j. Dec 22 '17 at 12:24
  • I just ran up a Windows XP in VirtualBox and the command exactly as given in my answer works fine... – Mark Setchell Dec 22 '17 at 12:31
  • Strange, now it works for me too. Probably I made some error while copy-pasting. – john c. j. Dec 22 '17 at 12:35