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-05 12:46
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to batch rename folders View 1,139 Replies 3
Original Poster Posted 2007-08-05 13:16 ·  中国 北京 鹏博士BGP
初级用户
Credits 126
Posts 47
Joined 2007-07-02 17:00
19-year member
UID 92952
Gender Male
Status Offline
For example, under my E:\11 folder there are a lot of folders, 132132 ghsdkj hkw437....... the names have no pattern. I want to rename them according to a certain pattern, for example 001 002 003......
What should I do?
I searched the forum, and there are only ones about renaming files, none about renaming folders.
Floor 2 Posted 2007-08-05 16:04 ·  中国 香港 腾讯云
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Use

ren command or move command
Floor 3 Posted 2007-08-05 16:26 ·  中国 北京 鹏博士
初级用户
Credits 126
Posts 47
Joined 2007-07-02 17:00
19-year member
UID 92952
Gender Male
Status Offline
I of course know to use the ren command.
Help me take a look at what's wrong with what I wrote.
@echo off
dir /a /b E:\11 >1.txt
for /f %%i in (1.txt) do (for /L %%c in (1,1,20) do (ren e:\11\%%i %%c))


The first time I run it it's fine, but the next time I run it (after new folders have been added inside) it goes wrong, saying it can't find the file or that the name is duplicated.
Floor 4 Posted 2007-08-05 16:46 ·  中国 香港 腾讯云
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
@echo off 
set num1=0
for /f "delims=" %%i in ('dir /ad /b') do (
set /a num1+=1
call set num1=0000%%num1%%
call ren "%%i" %%num1:~-3%%
)
pause


Look at this. If the number of folders is under 1000, this will work.

If it exceeds one thousand, change call ren "%%i" %%num1:~-4%%

Set it to however many digits the quantity has.
Forum Jump: