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-01 12:40
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] How to implement batch renaming of files (1.rm --> 001.rm, etc.) View 2,104 Replies 8
Original Poster Posted 2005-02-20 00:00 ·  中国 山东 淄博 联通
初级用户
Credits 111
Posts 4
Joined 2005-02-20 00:00
21-year member
UID 36346
Gender Male
Status Offline
I have downloaded some files from the internet, and the command rules are like 1.rm, 2.rm... 11.rm, 12.rm... 100.rm, etc.

It's not very pleasant to sort by file name in Windows Explorer. Is there a convenient way under DOS to uniformly complete to three (or a specified number of) digits, that is, 1.rm --> 001.rm, 11.rm --> 011.rm, etc.

Also, in some cases, there are some prefixes in front of the number, such as sanguo1.rm, which should be changed to sanguo001.rm, etc.

I've been trying the for command for a long time and it doesn't work. I'm asking for help from all the experts, please give more advice.
Floor 2 Posted 2005-02-20 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
http://www.msfans.net/bbs/
Floor 3 Posted 2005-02-20 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
If your system is of the NT architecture, you can use the FOR statement for /l %%a in (1,1,99) do ren sanguo%%a.txt 0%%a.txt
http://www.msfans.net/bbs/
Floor 4 Posted 2005-02-20 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
for /l %%a in (1,1,99) do ren sanguo%%a.rm 0%%a.rm
http://www.msfans.net/bbs/
Floor 5 Posted 2005-02-20 00:00 ·  中国 山东 淄博 联通
初级用户
Credits 111
Posts 4
Joined 2005-02-20 00:00
21-year member
UID 36346
Gender Male
Status Offline
Thanks to the person above.

I'm using Windows 2000, and all the answers you provided should be correct.

I just tried it and it basically worked. It did add a 0 in front of each file. Although it's not exactly what I wanted (where I could distinguish the number of digits and pad them to the corresponding number of digits, like sg1.rm to sg001.rm and sg10.rm to sg010.rm by adding only one 0), it's a bit cumbersome, but I can just use the command twice.

Also: I don't quite understand the grammar explanation yet. I'm looking for Windows help. If it's convenient for you, can you explain it a little?
Floor 6 Posted 2005-02-20 00:00 ·  中国 山东 淄博 联通
初级用户
Credits 111
Posts 4
Joined 2005-02-20 00:00
21-year member
UID 36346
Gender Male
Status Offline
Got it.
I know why it didn't work for a long time before. The thinking was wrong.
Before, my thinking was limited to getting variables from the file name. I never thought that I could directly use 1 - 99 as variables.
I originally used it like this: for %a in (sg?.rm) do echo ren %a...
It's obvious that the above sentence can list all the files that meet the requirements, but in the actual command, because the digital part cannot be obtained, it can only fail.

OK, thank you again to the upstairs. Not only did it solve the problem, but it also taught me a new way of thinking.
Floor 7 Posted 2005-02-20 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
Without everyone learning from each other and practicing more, we can't find the answer
http://www.msfans.net/bbs/
Floor 8 Posted 2005-02-20 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
It's a bit troublesome with commands. Install a Mop Rename Utility, and you can change it however you want.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 9 Posted 2005-02-21 00:00 ·  中国 重庆 渝中区 电信
银牌会员
★★★
Credits 2,165
Posts 730
Joined 2004-04-21 00:00
22-year member
UID 22966
Gender Male
Status Offline
Indeed, I've learned a lot! The nt command line is really quite different from DOS!
Forum Jump: