【问题标题】:Convert to another folder转换到另一个文件夹
【发布时间】:2018-06-05 02:06:30
【问题描述】:

这个命令对我有用:

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"

现在,假设我有这个文件层次结构:

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

我应该如何修改现有脚本以输出小文件夹中的文件,如下所示?

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

我尝试使用%~dp0,但目前没有运气。

【问题讨论】:

  • 尝试发布非工作脚本。

标签: batch-file cmd imagemagick image-manipulation imagemagick-convert


【解决方案1】:

我想我明白了,但在尝试之前请先备份:

mogrify -path small -format png *.jpg

我没有现成的 Windows 可供测试,但根据您的 cmets 尝试:

convert *.jpg -set filename:f "%%t.%%e" "small/%%[filename:f].png"

【讨论】:

  • 马克,谢谢。目前我正在尝试使用convert 而不是mogrify 来避免文件名冲突,如下所述:stackoverflow.com/questions/44284542/…
  • 我已经更新了我的答案,请再看看。在 Windows 上,您可能需要一个反斜杠,或者在斜杠之前添加一个插入符号 (^)。
  • 不确定文件名冲突实际上是如何发生的,因为所有文件都来自同一个目录,所以它们必须已经是唯一的。
  • 是的,反斜杠,但不起作用。我很早就尝试过类似的方法,但没有运气
  • 我刚刚在 VirtualBox 中运行了一个 Windows XP,并且我的答案中给出的命令运行良好......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-14
  • 2021-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多