中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-12 00:05
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Can such batch renaming make the end of the file name an increasing sequence?
Printable Version  2,847 / 23
Floor1 laineve Posted 2010-08-05 22:41
新手上路 Posts 18 Credits 18
a.txt ,b.txt,c.txt
I want to change them into a1.txt, b2.txt, c3.txt
Floor2 wangyang331407 Posted 2010-08-07 16:26
初级用户 Posts 28 Credits 28
@echo off
setlocal enabledelayedexpansion
set num=0
for /f %%i in ('dir /a-d /b ?.txt') do (
set /a num+=1
echo !num!
ren %%i ?!num!.txt
)
pause & exit
Floor3 laineve Posted 2010-08-07 18:17
新手上路 Posts 18 Credits 18
Thanks, I'll go study it..
Floor4 laineve Posted 2010-08-07 18:28
新手上路 Posts 18 Credits 18
It seems that it can't be flexibly used... If you change the name, it won't be okay...
Floor5 churui007 Posted 2010-08-07 18:37
新手上路 Posts 12 Credits 12
The key is that you didn't write out the arrangement rules.
Floor6 wangyang331407 Posted 2010-08-07 20:19
初级用户 Posts 28 Credits 28
I'm also just a beginner. Have you figured out a better method? Share it with us, please.
Floor7 jike106397 Posted 2010-08-08 00:54
新手上路 Posts 3 Credits 9
Take a good look, this place is really big!!
Floor8 laineve Posted 2010-08-08 09:48
新手上路 Posts 18 Credits 18
Rules? No way, I feel the rules are very obvious...
I want to add 1 to n at the end of several files, with any file names...
But now I feel it's not appropriate... I want them to be sorted normally, preferably placed before
For example: Originally there are n files (each name is different, but of the same type, for the convenience of these file names are all replaced with *),
Now I want to add serial numbers in front of these files: 1*.txt, 2*.txt....N*.txt
Floor9 laineve Posted 2010-08-08 09:50
新手上路 Posts 18 Credits 18
The above * is any normal file name
Floor10 churui007 Posted 2010-08-08 09:57
新手上路 Posts 12 Credits 12
What you said is like having 6 children at home and the father randomly arranging their order of seniority regardless of their ages.

The rules I mentioned, such as sorting by file size, or by file name, or by modification time, etc.
Floor11 laineve Posted 2010-08-08 13:53
新手上路 Posts 18 Credits 18
Hehe, that's what I meant. If you have a way to add serial numbers in front of them in order according to the modification time or file size, you are also welcome to share it.
Floor12 churui007 Posted 2010-08-08 19:58
新手上路 Posts 12 Credits 12
dir 文件夹
Extract file names
findstr /i txt
Apply the code from floor 2 to complete
Do it yourself specifically
Floor13 laineve Posted 2010-08-08 20:10
新手上路 Posts 18 Credits 18
I can't write or won't ask, let's see...

(注:原句中有比较随意的口语化表达,按照要求尽量直译,同时保持原本的表述风格)
Floor14 laineve Posted 2010-08-09 00:07
新手上路 Posts 18 Credits 18
No response... It seems that the person on the 12th floor is someone who talks big but is short on action. He started with sarcasm, and now it turns out he really can't.
Floor15 slore Posted 2010-08-09 08:32
铂金会员 Posts 2,478 Credits 5,212
If you just wait for others to bring you food, you will starve to death one day...

Just look at the code on floor 2 and exchange the positions by yourself...

@echo off
setlocal enabledelayedexpansion
set num=0
for /f "delims=" %%i in ('dir /a-d /b *.txt') do (
set /a num+=1
echo %%~ni
ren "%%i" "!num!%%~ni.txt"
)
pause & exit
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023