簡明的批處理文件:
for %%f in (*.htm) do set name=%%~nf
ren * "%name%.*"
相同的警告作爲n01d的答案。另外,不要把你的批處理文件放在同一個目錄下。
編輯:
這裏是一個示例會話顯示該批處理文件重命名所有的fiiles到.htm文件的名稱:
D:\tmp\kktmp>dir
Volume in drive D has no label.
Volume Serial Number is 4EDE-41E1
Directory of D:\tmp\kktmp
14/07/2016 12:06 <DIR> .
14/07/2016 12:06 <DIR> ..
14/07/2016 12:05 0 Author Name - Book Title - The Billionaires Revenge.htm
14/07/2016 12:06 0 Book Title - The Billiona - Author Name.azw3
14/07/2016 12:06 0 Book Title - The Billiona - Author Name.epub
14/07/2016 12:06 0 Book Title - The Billiona - Author Name.mobi
14/07/2016 12:06 0 Book Title - The Billiona - Author Name.pdf
5 File(s) 0 bytes
2 Dir(s) 52,725,227,520 bytes free
D:\tmp\kktmp>type ..\t.bat
for %%f in (*.htm) do set name=%%~nf
ren * "%name%.*"
D:\tmp\kktmp>..\t.bat
D:\tmp\kktmp>for %f in (*.htm) do set name=%~nf
D:\tmp\kktmp>set name=Author Name - Book Title - The Billionaires Revenge
D:\tmp\kktmp>ren * "Author Name - Book Title - The Billionaires Revenge.*"
D:\tmp\kktmp>dir
Volume in drive D has no label.
Volume Serial Number is 4EDE-41E1
Directory of D:\tmp\kktmp
14/07/2016 12:37 <DIR> .
14/07/2016 12:37 <DIR> ..
14/07/2016 12:06 0 Author Name - Book Title - The Billionaires Revenge.azw3
14/07/2016 12:06 0 Author Name - Book Title - The Billionaires Revenge.epub
14/07/2016 12:05 0 Author Name - Book Title - The Billionaires Revenge.htm
14/07/2016 12:06 0 Author Name - Book Title - The Billionaires Revenge.mobi
14/07/2016 12:06 0 Author Name - Book Title - The Billionaires Revenge.pdf
5 File(s) 0 bytes
2 Dir(s) 52,724,703,232 bytes free
你想做的事,對於單文件夾還是遞歸? –
僅限一個文件夾。謝謝 –