bat001-批處理更改文件名-批量更改文件名(替換文件名中的空格)

@echo off
mode con cols=50 lines=20
color 0a
setlocal enabledelayedexpansion
echo --------------------------------------------
echo 【批量更改當前目錄中所有文件的文件名】-
echo 【不包括子文件夾】-
echo --------------------------------------------
echo 【請確認是否鎖定文件類型】
echo 【0-鎖定(默認)/1-不鎖定】
echo 【建議鎖定,這樣批量改名不會影響文件類型(後綴)】
echo 【如果要替換文件後綴名:】
echo       【例如:將.jgp替換成.bmp】
echo       【請輸入1】
echo 【回車確認】
set str_type=0
set /P str_type=【默認0】:
set /P str1=輸入被替換字符【非空字符】【回車】:
set /P str2=輸入新字符【空字符直接回車】:
set /P str_start=輸入前綴字符【空字符直接回車】:
set /P str_end=輸入後綴字符【空字符直接回車】:
echo str_type=%str_type%
if %str_type%==0 (
    for /f "tokens=*" %%i in ('dir/b') do (
        if not "%%i"=="%~nx0" (
            set fn=%%~ni
            set fn=!fn:%str1%=%str2%!
            set fn=%str_start%!fn!%str_end%%%~xi
            ren "%%i" !fn!
            echo !fn!
        )
    )
) else (
if %str_type%==1 (
    for /f "tokens=*" %%i in ('dir/b') do (
        if not "%%i"=="%~nx0" (
            set fn=%%i
            set fn=!fn:%str1%=%str2%!
            set fn=%str_start%!fn!%str_end%
            ren "%%i" !fn!
            echo !fn!
        )
    )
)
)
pause
:--------------------------------------
set str1=9734
set str2=9077
set str3=0
set str4=%str1%%str2%%str3%@
:--------------------------------------
echo %str4%com
pause

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章