Require:
1. The order of content cannot be changed
2. Rename all jpg files in the current directory in the form of serial numbers, such as: from 1-16
3. If there are 16 files, they must be renamed to 1-16. Serial numbers after 16 are not allowed
content:
The content in it is actually the list of jpg files under the current folder.
It is required to rename all jpg files in the current folder as serial numbers.
But you can only get all the jpg file names in the current folder from .
Rename files with sequence numbers, and there are many traps, but if you use dir or for commands to obtain file names, the order of acquisition will be regular, which will lead to some problems that cannot be reflected.
@echo on
setlocal enabledelayedexpansion
set n=0
set n1=0
for /f "tokens=*" %%a in () do (
set /a n+=1
ren %%a t!n!.jpg
)
:loop
set /a n1+=1
ren t%n1%.jpg %n1%.jpg&&goto :loop
exit
The second method
It seems to be easier
@echo off
ren *.jpg t*.jpg
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir/b "t*.jpg"') do (
set str=%%a&set str=!str:~1!
ren "%%a" "!str!"
)
pause
1. The order of content cannot be changed
2. Rename all jpg files in the current directory in the form of serial numbers, such as: from 1-16
3. If there are 16 files, they must be renamed to 1-16. Serial numbers after 16 are not allowed
content:
Copy the codeThe code is as follows:
The content in it is actually the list of jpg files under the current folder.
It is required to rename all jpg files in the current folder as serial numbers.
But you can only get all the jpg file names in the current folder from .
Rename files with sequence numbers, and there are many traps, but if you use dir or for commands to obtain file names, the order of acquisition will be regular, which will lead to some problems that cannot be reflected.
Copy the codeThe code is as follows:
@echo on
setlocal enabledelayedexpansion
set n=0
set n1=0
for /f "tokens=*" %%a in () do (
set /a n+=1
ren %%a t!n!.jpg
)
:loop
set /a n1+=1
ren t%n1%.jpg %n1%.jpg&&goto :loop
exit
The second method
It seems to be easier
Copy the codeThe code is as follows:
@echo off
ren *.jpg t*.jpg
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir/b "t*.jpg"') do (
set str=%%a&set str=!str:~1!
ren "%%a" "!str!"
)
pause