我正在尝试重命名目录中的一组文件,这些文件都包含我想要删除的文件名中的一部分。 名称的例子是:
此?392!。的 111 thepartIwanttoremove.exe
thankyouall。的 222 thepartIwanttoremove.exe
我的代码是:
forfiles /S /M *.111thepartIwanttoremove.exe /C "cmd /c rename @file @fname.doc"
ren ???.111thepartIwanttoremove.* ???.doc
ren ????.111thepartIwanttoremove.* ????.doc
ren ?????.111thepartIwanttoremove.* ?????.doc (and so on)
forfiles /S /M *.222thepartIwanttoremove.exe /C "cmd /c rename @file @fname.jpg"
ren ???.222thepartIwanttoremove.* ???.jpg
ren ????.222thepartIwanttoremove.* ????.jpg
ren ?????.222thepartIwanttoremove.* ?????.jpg (and so on)
所以我想要一个例子:
123876.111thepartIwanttoremove.exe
看起来像这样:
123876.doc
我可以使用什么功能删除名称的。* thepartIwanttoremove.exe部分,而不用#34;?"?"?
写出这么多行非常感谢你的帮助。
答案 0 :(得分:0)
假设所有文件都有三个由句点分隔的文件名部分,这种代码样式应该适合你。
for /F "tokens=1-3 delims=." %%G in ('dir /a-d /b *.111*.exe') do rename "%%G.%%H.%%I" "%%G.doc"
for /F "tokens=1-3 delims=." %%G in ('dir /a-d /b *.222*.exe') do rename "%%G.%%H.%%I" "%%G.jpg"