您可以使用两个批处理文件命令命令做到这一点:“FOR /”
类型从命令提示符查看命令语法:
首先进入包含照片的目录:
C:\> cd /d "D:\Pictures"
D:\Pictures>
那么你的内部“d:\ Pictures”文件夹,运行这两个命令:
for /r %f in (*.tga) do if exist "%~df%~pf%~nf.png" del "%f"
for /r %f in (*.tga) do if exist "%~df%~pf%~nf.jpg" del "%f"
测试这样的命令时请小心,最好在做好备份之后!你已被警告。将对于(命令)
/r Recurse subdirectories
%f Variable used to represent each matching file
(*.tga) File Spec to search for
do part of for command, following command executed for each match
if exist XXX del XXX
~d between the %f (%~df), returns only the drive (d:)
~p between the %f (%~pf), returns only the path (\path\)
~n between the %f (%~nf), returns only the filename without extension
...then appending .png or .jpg to end of those...
~f returns the full filename, including path
另外,如果你需要把这样的命令批处理文件中,你需要加倍的变量名百分号 :命令的
击穿,如:
for /r %%f in (*.tga) do if exist "%%~df%%~pf%%~nf.png" del "%%f"
for /r %%f in (*.tga) do if exist "%%~df%%~pf%%~nf.jpg" del "%%f"
欢迎来到Stack Overflow。请参加2分钟的[游览]。 此外,打开[帮助]并至少阅读[问]。然后,[编辑]你的问题提供[mcve]。 只询问代码的问题过于宽泛,很可能会[搁置或关闭](http://stackoverflow.com/help/closed-questions)。 – JosefZ
如果你不熟悉'powershell'-这是微软替代'Dos'类型'命令提示符'。所以你可以从你的程序菜单运行'powershell',复制粘贴我下面提供的解决方案,点击输入两次 - 脚本将运行... – Plirkee