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-11 07:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Batch rename HTML files according to a certain rule View 732 Replies 8
Original Poster Posted 2009-02-04 11:05 ·  中国 上海 华为云
中级用户
★★
Credits 234
Posts 119
Joined 2007-04-22 11:09
19-year member
UID 86077
Gender Male
Status Offline
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?
Floor 2 Posted 2009-02-04 13:35 ·  中国 上海 华为云
中级用户
★★
Credits 234
Posts 119
Joined 2007-04-22 11:09
19-year member
UID 86077
Gender Male
Status Offline
Bump it myself~~~~~~~~~~
Floor 3 Posted 2009-02-04 15:21 ·  中国 北京 联通
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
Use for and findstr to split, extract, and process the string, then use ren to rename

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 4 Posted 2009-02-04 15:25 ·  中国 上海 华为云
中级用户
★★
Credits 234
Posts 119
Joined 2007-04-22 11:09
19-year member
UID 86077
Gender Male
Status Offline
Could you be a bit more detailed, man?
Floor 5 Posted 2009-02-04 15:34 ·  中国 北京 联通
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
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?

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 6 Posted 2009-02-04 16:02 ·  中国 江苏 苏州 电信
初级用户
Credits 20
Posts 13
Joined 2009-01-05 14:58
17-year member
UID 135829
Gender Male
Status Offline
Floor 7 Posted 2009-02-04 17:38 ·  美国 华盛顿州 金 雷德蒙德 Microsoft
初级用户
★★
Credits 100
Posts 93
Joined 2009-01-14 15:04
17-year member
UID 136661
Gender Male
From 湖南
Status Offline
What if the title between <title></title> contains <> characters? Can the poster above revise it a bit?
Floor 8 Posted 2009-02-04 18:24 ·  美国 华盛顿州 金 雷德蒙德 Microsoft
初级用户
★★
Credits 100
Posts 93
Joined 2009-01-14 15:04
17-year member
UID 136661
Gender Male
From 湖南
Status Offline
Floor 9 Posted 2009-02-04 18:32 ·  美国 华盛顿州 金 雷德蒙德 Microsoft
初级用户
★★
Credits 100
Posts 93
Joined 2009-01-14 15:04
17-year member
UID 136661
Gender Male
From 湖南
Status Offline
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
Forum Jump: