在某破站上批量下載了一些文件,文件名前面都會帶有序號和網站名,影響原文件帶序號的排序,寫了個簡單的批處理,直接刪除文件名前N個字符。
原文件名:
0001.比例比例-零基礎學習-01 - 購物導航.flv
0002.比例比例-零基礎學習-013- 網頁.flv
0003.比例比例-零基礎學習-02 - 遊戲加速.flv
運行bat:
Please enter the file suffix : flv
Please enter how many characters to cut out : 10
(中文按1個字符來處理)
修改後,文件名爲:
零基礎學習-01 - 購物導航.flv
零基礎學習-02 - 遊戲加速.flv
零基礎學習-013- 網頁.flv
@echo off
setlocal enabledelayedexpansion
set /p format=Please enter the file suffix :
set /p deletenum=Please enter how many characters to cut out :
for /r %%i in (.) do (
for /f "delims=" %%a in (' dir /b "%%i\*.%format%" 2^>nul ') do (
set "t=%%~na"
ren "%%i\%%a" "!t:~%deletenum%!%%~xa"
)
)
在需修改文件名的同個目錄下,創建一個txt文件,粘貼以上代碼,保存後修改後綴爲bat,雙擊運行。