China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-11 23:09
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Can such batch renaming make the end of the file name an increasing sequence? View 2,843 Replies 23
Original Poster Posted 2010-08-05 22:41 ·  中国 河北 廊坊 电信
新手上路
Credits 18
Posts 18
Joined 2010-06-11 20:59
16-year member
UID 168643
Gender Male
Status Offline
a.txt ,b.txt,c.txt
I want to change them into a1.txt, b2.txt, c3.txt
Floor 2 Posted 2010-08-07 16:26 ·  中国 上海 电信
初级用户
Credits 28
Posts 28
Joined 2010-07-28 11:06
16-year member
UID 171355
Gender Male
Status Offline
@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
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
laineve +1 2010-08-07 18:16
Floor 3 Posted 2010-08-07 18:17 ·  中国 河北 廊坊 电信
新手上路
Credits 18
Posts 18
Joined 2010-06-11 20:59
16-year member
UID 168643
Gender Male
Status Offline
Thanks, I'll go study it..
Floor 4 Posted 2010-08-07 18:28 ·  中国 河北 廊坊 电信
新手上路
Credits 18
Posts 18
Joined 2010-06-11 20:59
16-year member
UID 168643
Gender Male
Status Offline
It seems that it can't be flexibly used... If you change the name, it won't be okay...
Floor 5 Posted 2010-08-07 18:37 ·  中国 山西 太原 联通
新手上路
Credits 12
Posts 12
Joined 2010-08-03 11:45
16-year member
UID 171662
Gender Male
Status Offline
The key is that you didn't write out the arrangement rules.
Floor 6 Posted 2010-08-07 20:19 ·  中国 上海 电信
初级用户
Credits 28
Posts 28
Joined 2010-07-28 11:06
16-year member
UID 171355
Gender Male
Status Offline
I'm also just a beginner. Have you figured out a better method? Share it with us, please.
Floor 7 Posted 2010-08-08 00:54 ·  中国 广东 深圳 电信
新手上路
Credits 9
Posts 3
Joined 2010-05-31 17:33
16-year member
UID 168003
Gender Male
Status Offline
Take a good look, this place is really big!!
Floor 8 Posted 2010-08-08 09:48 ·  中国 河北 廊坊 电信
新手上路
Credits 18
Posts 18
Joined 2010-06-11 20:59
16-year member
UID 168643
Gender Male
Status Offline
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
Floor 9 Posted 2010-08-08 09:50 ·  中国 河北 廊坊 电信
新手上路
Credits 18
Posts 18
Joined 2010-06-11 20:59
16-year member
UID 168643
Gender Male
Status Offline
The above * is any normal file name
Floor 10 Posted 2010-08-08 09:57 ·  中国 山西 太原 联通
新手上路
Credits 12
Posts 12
Joined 2010-08-03 11:45
16-year member
UID 171662
Gender Male
Status Offline
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.
Floor 11 Posted 2010-08-08 13:53 ·  中国 河北 廊坊 电信
新手上路
Credits 18
Posts 18
Joined 2010-06-11 20:59
16-year member
UID 168643
Gender Male
Status Offline
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.
Floor 12 Posted 2010-08-08 19:58 ·  中国 山西 太原 联通
新手上路
Credits 12
Posts 12
Joined 2010-08-03 11:45
16-year member
UID 171662
Gender Male
Status Offline
dir 文件夹
Extract file names
findstr /i txt
Apply the code from floor 2 to complete
Do it yourself specifically
Floor 13 Posted 2010-08-08 20:10 ·  中国 河北 廊坊 电信
新手上路
Credits 18
Posts 18
Joined 2010-06-11 20:59
16-year member
UID 168643
Gender Male
Status Offline
I can't write or won't ask, let's see...

(注:原句中有比较随意的口语化表达,按照要求尽量直译,同时保持原本的表述风格)
Floor 14 Posted 2010-08-09 00:07 ·  中国 河北 廊坊 电信
新手上路
Credits 18
Posts 18
Joined 2010-06-11 20:59
16-year member
UID 168643
Gender Male
Status Offline
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.
Floor 15 Posted 2010-08-09 08:32 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
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
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Forum Jump: