中国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-11 07:04
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » [Help] Batch rename HTML files according to a certain rule
Printable Version  730 / 8
Floor1 w1314ich Posted 2009-02-04 11:05
中级用户 Posts 119 Credits 234
I have a batch of HTML files that need to be renamed. The rule is: read the aaa inside
<title>aaa</title> in the HTML content, then use aaa to name this HTML file. How can this be done?
Floor2 w1314ich Posted 2009-02-04 13:35
中级用户 Posts 119 Credits 234
Bump it myself~~~~~~~~~~
Floor3 yishanju Posted 2009-02-04 15:21
银牌会员 Posts 1,357 Credits 1,488
Use for and findstr to split, extract, and process the string, then use ren to rename
Floor4 w1314ich Posted 2009-02-04 15:25
中级用户 Posts 119 Credits 234
Could you be a bit more detailed, man?
Floor5 yishanju Posted 2009-02-04 15:34
银牌会员 Posts 1,357 Credits 1,488
Originally posted by w1314ich at 2009-2-4 15:25:
Could you be a bit more detailed, man?


I want to say the same thing to you too

Do you dare post a copy of the HTML file contents here?
Floor6 BaseCoder Posted 2009-02-04 16:02
初级用户 Posts 13 Credits 20
Floor7 zhengqian529 Posted 2009-02-04 17:38
初级用户 Posts 93 Credits 100 From 湖南
What if the title between <title></title> contains <> characters? Can the poster above revise it a bit?
Floor8 zhengqian529 Posted 2009-02-04 18:24
初级用户 Posts 93 Credits 100 From 湖南
Floor9 zhengqian529 Posted 2009-02-04 18:32
初级用户 Posts 93 Credits 100 From 湖南
There's one thing not so good about the code above. I just looked at it, and if there are spaces, there will be problems, so change the code to:
@echo off
Setlocal EnableDelayedExpansion

for /f "delims=" %%a in ('dir /b *.htm') do (
if exist "%%a" (
for /f “delims=” %%b in ('findstr /i "\<title\>.*\<\/title\>" %%a') do (
set var=%%b
ren "%%a" "!var:~7,-8!.htm"
)
)
)
Endlocal
pause
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023