中国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-09-23 14:41
47,812 topics / 349,917 posts / today 0 new / 48,273 members
DOS批处理 & 脚本技术(批处理室) » [Help] How to implement batch renaming of files (1.rm --> 001.rm, etc.)
Printable Version  2,198 / 8
Floor1 coolstar14 Posted 2005-02-20 00:00
初级用户 Posts 4 Credits 111
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.
Floor2 chenhui530 Posted 2005-02-20 00:00
高级用户 Posts 273 Credits 772
Floor3 chenhui530 Posted 2005-02-20 00:00
高级用户 Posts 273 Credits 772
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
Floor4 chenhui530 Posted 2005-02-20 00:00
高级用户 Posts 273 Credits 772
for /l %%a in (1,1,99) do ren sanguo%%a.rm 0%%a.rm
Floor5 coolstar14 Posted 2005-02-20 00:00
初级用户 Posts 4 Credits 111
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?
Floor6 coolstar14 Posted 2005-02-20 00:00
初级用户 Posts 4 Credits 111
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.
Floor7 chenhui530 Posted 2005-02-20 00:00
高级用户 Posts 273 Credits 772
Without everyone learning from each other and practicing more, we can't find the answer
Floor8 Climbing Posted 2005-02-20 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
It's a bit troublesome with commands. Install a Mop Rename Utility, and you can change it however you want.
Floor9 bush Posted 2005-02-21 00:00
银牌会员 Posts 730 Credits 2,165
Indeed, I've learned a lot! The nt command line is really quite different from DOS!
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023