Example 1
@echo off & setlocal enabledelayedexpansion echo -==File name replacement(Remove the file name_v2and_V3)==- echo. echo. set /p folder=Please enter a path: for /r %folder% %%i in (*) do ( set file=%%i set file=!file:_v2=! set file=!file:_v3=! if %%i neq !file! (move "%%i" "!file!") ) echo. echo. echo All file names are replaced。 echo Press any key to exit。 pause>nul
Example 2 Batch replacement modification file name
When you have many similar files, and the file names can be very regular but somewhat irregular... you can try this batch processing.
@echo off echo.&echo. title Batch replacement of partial strings in filenames&color 3f echo Note: echo This batch process can batch replace the same characters of all file names in the folder where this file is located. echo.&echo.&echo.&echo.&echo.&echo. echo.&set /p strtemp3= Please enter the file type to replace: echo.&set /p strtemp1= Please enter the string to replace(Replaceable spaces): echo.&set /p strtemp2= Please enter the replaced string(Delete and go directly to the car): setlocal enabledelayedexpansion for /f "delims=" %%a in ('dir /a /b *.%strtemp3%') do ( set nobird=%%a ren "%%~a" "!nobird:%strtemp1%=%strtemp2%!") echo.&echo.&echo.&echo.&echo Done! pause
Batch rename to the implementation code that increases by number
1. Collectively select right-click to rename the name of the file you want to rename it to a non-number
2. Save this command as bat in the directory to be renamed, change the name to (or change it to something else by yourself, and change the code as follows)
@echo off setlocal enabledelayedexpansion for %%x in (*) do ( if not "%%x"=="" ( set /a sum+=1 rename "%%x" "!sum!.txt" ) ) echo Batch renaming is completed! pause
3. Change different suffix names according to your needs
Batch commands implement file specification renaming
Usually, we rarely use batch commands to realize this function through online learning and share it with friends in need.
Implement the name of all files (excluding subfolders) with the specified suffix name (such as JPG) in the folder where the batch is located is the file name with the specification.
@echo off&setlocal EnableDelayedExpansion set a=0 for /f "delims=" %%i in ('dir /b *.jpg') do ( if not "%%~ni"=="%~n0" ( if !a! LSS 10 ( ren "%%i" "sample0000!a!.jpg")else if !a! LSS 100 ( ren "%%i" "sample000!a!.jpg")else if !a! LSS 1000 ( ren "%%i" "sample00!a!.jpg")else if !a! LSS 10000 ( ren "%%i" "sample0!a!.jpg")else ( ren "%%i" "sample!a!.jpg") set/a a+=1 ) )
The above is the detailed content of the batch code for modifying file names. For more information about modifying file names, please pay attention to my other related articles!