Article directory
foreword
In order to achieve the purpose of changing file names in batches, I tried to import them into excel to modify names and cmd scripts in batches, and finally felt that cmd scripts are easy to use. Of course, the essence is to use cmd commands to achieve batch editing
Tip: The following is the text of this article, and the following cases are for reference
1. How to use excel to import and modify the file name?
Reference article: cmd batch extraction of file names in folders
Under Windows environment, use CMD command to batch modify file names
Note: Since Win10 shift + right click opens powershell (unrecognized dir /b
command), not cmd, so it is recommended CMD
to open cmd directly by typing in the address bar
Next is the export file name
dir /b *.pdf*>文献统计.csv
Batch editing the names in the table in various ways
is often used:
1. Data sorting: How to automatically sort the data imported by Excel
2. File name directory formation needs
="ren "&A1&" "&B1
3. How to batch add fixed characters to existing cells in Excel
? It is too troublesome and cannot meet my needs, so I give up
Two, CMD script batch editing
1.
code show as below:
@echo off&setlocal EnableDelayedExpansion
set a=1
for /f "delims=" %%i in ('dir /b *.wav') do (
if not "%%~ni"=="%~n0" (
if !a! LSS 10 (ren "%%i" "sp0!a!_airport_sn0.wav") else ren "%%i" "sp!a!_airport_sn0.wav"
set/a a+=1
)
)
Command explanation:
set a = 1 is to set the incremented variable, the starting value of the file increment or decrement
The .wav in the square brackets (dir /b .wav) in the third line can be replaced with any matching string, such as matching a file that contains string and the suffix is jpg, then you can (dir /b string .jpg )
The third line is to say that if the file name is the same as itself, it will not be replaced, otherwise the script will change itself when it runs
The if judgment in the fifth line is for unified numbering and naming. When a is less than 10, for example, a is equal to 1, the name is 01; "sp0!a!_airport_sn0.wav" in the double quotes is the naming format of the file name, which can be arbitrary replace.
set/a a+=1 , set increment variable, can also be set to decrement, or any increment and decrement interval
Note:
Please modify and copy the script to Notepad, and save it as a .bat file (ren.bat). Select "Any file" as the file type when saving as, and add .bat to the file name suffix.
Be sure to place this script under the folder that needs to be renamed, that is to say, this script should be placed in the same directory as the file that needs to be renamed.
@echo off&setlocal EnableDelayedExpansion
set a=1
for /f "delims=" %%i in ('dir /b *.jpg') do (
if not "%%~ni"=="%~n0" (
if !a! LSS 10 (ren "%%i" "car00!a!.jpg") else if !a! LSS 100 (ren "%%i" "car0!a!.jpg") else ren "%%i" "car!a!.jpg"
set/a a+=1
)
)`
@echo off&setlocal EnableDelayedExpansion
set a=445
for /f "delims=" %%i in ('dir /b *.jpg') do (
if not "%%~ni"=="%~n0" (
if !a! LSS 100 (ren "%%i" "00!a!.jpg") else ren "%%i" "!a!.jpg"
set/a a+=1
)
)