批处理文件:按字母顺序(可能是数字>)处理文件
我目前正在尝试使用 imagemagick 处理一堆文件 在Windows中使用批处理文件,它们都按数字编号 如下: 图片00 图片01, 图片02, ..., 图片010, 图片011, ..., 图片0100, image0101
等等,但是当我尝试处理它想要运行的文件时 image00、image01、image010、image0100、image0101、image0102 等。
我的代码如下
SETLOCAL 启用延迟扩展
设置计数=0
FOR %%a in (*.bmp) DO
(
IF !错误级别!==0
(
设置 TFILE=0!计数!
SET TFILE=地形!TFILE:~-4!.jpg
设置/计数+=1
ECHO %%a >output.txt
转换 %%a -压缩无损!TFILE!
)
)
有什么方法可以让它按顺序处理这些文件,目前我有一个解决方法,但这意味着当稍后使用图像时我必须不断更改一些脚本文件在。我宁愿让所有文件都具有相同的“地形”名称,并在后面添加递增的数字。
预先感谢各位!
I am currently trying to process a bunch of files with imagemagick
using a batch file in windows, they are all numbered numerically as
follows:
image00
image01,
image02,
...,
image010,
image011,
...,
image0100,
image0101
and so on, but when i try to process the file it wants to run though
image00, image01, image010, image0100, image0101, image0102 and so on.
my code is as follows
SETLOCAL EnableDelayedExpansion
SET COUNT=0
FOR %%a in (*.bmp) DO
(
IF !ERRORLEVEL!==0
(
SET TFILE=0!COUNT!
SET TFILE=Terrain!TFILE:~-4!.jpg
SET /A COUNT+=1
ECHO %%a >output.txt
convert %%a -compress LOSSLESS !TFILE!
)
)
is there any way i can make it so that it will process these files in order, for the time being i have a work-around but it means that i continually have to change some script files when the images are used later on. I would much rather have all of the files be the same 'Terrain' name with incrementing number following.
Thanks in advance guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能可以创建更多批处理代码来按顺序“排序”数字,但是,由于您可以使用 imagemagick,我想您还可以下载其他内容。我的建议是你可以尝试使用 GNU 排序(在 coreutils 中)。然后在批处理中,执行类似伪代码的操作
:
您可以检查 Windows 附带的排序是否具有数字排序选项。 (我上次检查它没有这个选项)。
you can probably create some more batch code to "sort" the numbers by order, however, since you can use imagemagick, i suppose you can also download other stuff. my suggestion is you can try and use GNU sort (in coreutils ). Then in your batch , do some thing like this
pseudocode :
you could probably check whether the sort that comes with Windows has a numerical sorting option. (the last time i check it doesn't have this option).
您可以将文件重命名为 image000 image001、image002、...、image010,
您可以将文件名拆分为如下所示:
You could rename the files to be image000 image001, image002, ..., image010,
You could split up the file name something like this:
它很难找到,因为从文档中看它并不明显。解决方案是将 FOR 命令与 dir 命令结合使用。我会做这样的事情:
It's hard to find, because it's not really obvious from the documentation. The solution is to use the FOR command in combination with the dir command. I would do something like this: