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-02 17:59
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Help! How to rename files with batch processing View 1,661 Replies 4
Original Poster Posted 2006-12-08 10:25 ·  中国 重庆 联通
初级用户
★★
Credits 105
Posts 77
Joined 2006-11-09 02:14
19-year member
UID 70077
Gender Male
From 重庆
Status Offline
A friend has a server. He asked me that he has a directory at d:\, and there are many subdirectories in d:\html, and there are many *.htm files in the subdirectories. How to use batch processing to change all *.htm to *.html. Please ask experts for guidance.
Floor 2 Posted 2006-12-08 10:31 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
```
@echo off
for /f "delims=" %%i in ('dir/b/s *.htm^|find ".htm"') do echo "%%i" "%%il"
pause
```
Floor 3 Posted 2006-12-08 10:50 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Brother zh159, the previous plan of using dir followed by find still might find folder names ending with .htm because dir didn't filter out folders. Adding the parameter /a-d to dir can eliminate the need for find. Modify the demo code based on 2F as follows:

@echo off
for /f "delims=" %%i in ('dir /a-d /b/s d:\html\*.htm') do echo "%%i" "%%il"
pause
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 4 Posted 2006-12-08 10:53 ·  中国 重庆 联通
初级用户
★★
Credits 105
Posts 77
Joined 2006-11-09 02:14
19-year member
UID 70077
Gender Male
From 重庆
Status Offline
Thank you very much, moderator. Because my internet speed is slow, just now I thought I didn't post successfully and reposted it again, but just now I found it was duplicated. I'm sorry, I didn't intentionally spam. Please delete that post. Thank you.
Floor 5 Posted 2006-12-08 12:28 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
```
@echo off
pushd d:\html
ren *.htm *.html 2>nul
for /r /d %%i in (*) do ren "%%i\*.htm" "%%i\*.html" 2>nul
popd
exit /b 0
```
Theoretically it works, not tested.
Forum Jump: