- '代码可用,扫码头像,随意赞助;有什么问题,可加QQ956535081及时沟通
- If LCase(Right(WSH.FullName,12)) = "\wscript.exe" Then
- CreateObject("WScript.Shell").Run "cmd /c cscript.exe -nologo """ & WSH.ScriptFullName & """&pause&exit"
- WSH.Quit
- End If
-
- Set fso=CreateObject("Scripting.FileSystemObject")
- RootPath=fso.GetFile(WSH.ScriptFullName).ParentFolder.Path
- arr=split("\ / : * ? \ "" < > | " & Chr(9)," ")
- getfile RootPath
-
- Function getfile(path)
- Set oFolder=fso.GetFolder(path)
- Set oSubFolders=oFolder.SubFolders
-
- Set oFiles=oFolder.Files
- For Each oFile In oFiles
- ext=fso.GetExtensionName(oFile.Path)
- If Lcase(ext) = "html" Or Lcase(ext) = "htm" Then
- text=gethtml(oFile.Path)
- title=gettitle(text)
- NewName=title & "." & ext
- WSH.echo oFile.Path & " --> " & NewName
- If title <> "" Then
- If Not fso.FileExists(oFile.ParentFolder.Path & "\" & NewName) Then
- oFile.Name=NewName
- Else
- WSH.echo "文件重名"
- End If
- End If
- End If
- Next
-
- For Each oSubFolder In oSubFolders
- getfile(oSubFolder.Path)
- Next
- Set oFolder=Nothing
- Set oSubFolders=Nothing
- End Function
-
- Function gethtml(ByVal htmlfile)
- htmltext=""
- Set ado=CreateObject("ADODB.Stream")
- ado.Type=2
- '注意html文件的编码,如果是gbk或gb2312,修改下面的"utf-8"为"gb2312"
- ado.Charset="utf-8"
- ado.Open
- ado.LoadFromFile htmlfile
- ado.Position=0
- htmltext=ado.ReadText
- ado.Close
- Set ado=Nothing
- gethtml=htmltext
- End Function
-
- Function gettitle(ByVal htmltext)
- htmltitle=""
- Set regex=New RegExp
- regex.Pattern="<title>(.+?)<\/title>"
- regex.IgnoreCase=True
- regex.Global = True
- Set matches=regex.Execute(htmltext)
- If matches.Count = 1 Then
- htmltitle=matches(0).SubMatches(0)
- For i=0 To Ubound(arr)
- htmltitle=replace(htmltitle,arr(i),"_")
- Next
- End If
- Set regex=Nothing
- gettitle=htmltitle
- End Function
复制代码
|