简体   繁体   English

使用cmd批处理查找具有相同文件名的所有文件

[英]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.

相关问题 Windows批处理文件以在文件名中查找字符串 - Windows Batch File to Find String in Filename 如何使用CMD制作批处理文件? - How to make a batch file using CMD? 使用批处理文件/CMD 切换窗口焦点 - Switch Window Focus using a Batch File/CMD 使用Windows批处理文件将多个文件从具有相同文件名的不同文件夹复制到一个公用文件夹 - Copy multiple files from different folder with same filename to one common folder using windows batch file 如何使用 Windows 批处理编程重命名与该文件夹内第一个文件的文件名相同的文件夹? - How to rename a folder the same as the filename of the first file inside that folder using Windows batch programming? 在某个日期之后使用cmd /批处理文件获取所有文件的递归修改或创建 - Using a cmd / batch file to get all the files recursively modified or created after a certain date 使用批处理文件以相同的扩展名顺序重命名所有文件 - rename all files sequentially with same extension using batch file 批处理文件检查文件夹中具有其他扩展名的相同文件名 - Batch file check same filename with other extension in folders 记录由任务计划程序运行的批处理文件的cmd输出,并将日期/时间保存在文件名中 - Log cmd output of batch file ran by task scheduler and save with date/time in filename CMD批处理文件中的失败 - failture in CMD batch file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM