[英]How to rename a folder the same as the filename of the first file inside that folder using Windows batch programming?
[英]Windows Batch File, how to rename and remove part of filename
我正在嘗試重命名目錄中的一組文件,這些文件都包含在我稍后要刪除的文件名中。 名稱示例如下:
這?392!。 第111話
謝謝你們。 第222話
我的代碼是:
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 部分,而不用寫這么多行“?”?
非常感謝您的幫助。
假設所有文件都包含由句點分隔的文件名的三個部分,這種代碼風格應該適合您。
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"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.