[英]Using cmd batch to find all the file with the same filename
For example, in a directory, I have N .eps files named name1.eps, name2.eps, ...
and also much more pdf files. 例如,在目录中,我有N个.eps文件,分别名为
name1.eps, name2.eps, ...
以及更多pdf文件。 But within these pdf files, there are exactly N pdf files with the same filename as eps files, that is name1.pdf, name2.pdf,...
. 但是在这些pdf文件中,恰好有N个pdf文件与eps文件具有相同的文件名,即
name1.pdf, name2.pdf,...
So I want a batch that can scan the current dir, give a list of all eps files and corresponding list of pdf files. 所以我想要一个可以扫描当前目录的批处理,给出所有eps文件的列表以及相应的pdf文件列表。
finally I want another batch named convert.bat
which takes two parameters to run a series of command as below 最后,我想要另一个名为
convert.bat
批处理,它需要两个参数来运行一系列命令,如下所示
convert.bat name1.eps name1.pdf
convert.bat name2.eps name2.pdf
.....
.....
the convert.bat
first compares the modified time of name.eps and name.pdf, and if the modified time of name.eps is newer than name.pdf, then it will run epstopdf name.eps
, otherwise it will do nothing. convert.bat
首先比较name.eps和name.pdf的修改时间,如果name.eps的修改时间比name.pdf更新,则它将运行epstopdf name.eps
,否则将不执行任何操作。
I am really a newbie in using cmd batch. 我真的是使用cmd批处理的新手。 could somebody teach me how to realize the whole process I mentioned above.
有人可以教我如何实现我上面提到的整个过程。 Thank you so much!
非常感谢!
I figure out a way. 我想办法。 The following batch file do the whole job.
以下批处理文件可以完成整个工作。
SETLOCAL ENABLEDELAYEDEXPANSION
for %%G in (*.eps) do @if not exist "%%~nG.pdf" (epstopdf "%%G") else (
(for /f "delims=" %%i in ('dir /B /O:D "%%G" "%%~nG.pdf"') do set newest=%%~xi) & (
if !newest!==.eps epstopdf "%%G"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.