中国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-06 04:05
48,039 topics / 350,124 posts / today 2 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » Batch rename files in folders using the folder name
Printable Version  770 / 1
Floor1 yywd Posted 2007-10-12 17:41
中级用户 Posts 130 Credits 358
Help:
How can I batch rename files inside folders using the folder name?
For example, folder f contains three folders: a, b, and c. Folder a contains two files, x and y; folder b contains three files, m, n, and s; folder c contains one file, k. How can I use a batch file to rename
the two files x and y in folder a under folder f to a1 and a2, rename the three files m, n, and s in folder b to b1, b2, and b3, and rename file k in folder c to c?
Floor2 yywd Posted 2007-10-12 19:16
中级用户 Posts 130 Credits 358
Solved already
@echo off
for /d %%i in (*) do (
call :rm "%%i"
)
pause
goto :eof

:rm
set num=0
for /r %1 %%a in (*.*) do (
set /a num+=1
call ren "%%a" "%~1%%num%%%%~xa"
)
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023