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-06 03:03
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch rename files in folders using the folder name View 769 Replies 1
Original Poster Posted 2007-10-12 17:41 ·  中国 广东 深圳 宝安区 电信
中级用户
★★
Credits 358
Posts 130
Joined 2005-11-12 16:29
20-year member
UID 45117
Status Offline
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?
Floor 2 Posted 2007-10-12 19:16 ·  中国 广东 深圳 宝安区 电信
中级用户
★★
Credits 358
Posts 130
Joined 2005-11-12 16:29
20-year member
UID 45117
Status Offline
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"
)
Forum Jump: