[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. '代码可用,扫码头像,随意赞助;有什么问题,可加QQ956535081及时沟通
  2. If LCase(Right(WSH.FullName,12)) = "\wscript.exe" Then
  3.     CreateObject("WScript.Shell").Run "cmd /c cscript.exe -nologo """ & WSH.ScriptFullName & """&pause&exit"
  4.     WSH.Quit
  5. End If
  6. Set fso=CreateObject("Scripting.FileSystemObject")
  7. RootPath=fso.GetFile(WSH.ScriptFullName).ParentFolder.Path
  8. arr=split("\ / : * ? \ "" < > | " & Chr(9)," ")
  9. getfile RootPath
  10. Function getfile(path)
  11.     Set oFolder=fso.GetFolder(path)
  12.     Set oSubFolders=oFolder.SubFolders
  13.       
  14.     Set oFiles=oFolder.Files
  15.     For Each oFile In oFiles
  16.         ext=fso.GetExtensionName(oFile.Path)
  17.         If Lcase(ext) = "html" Or Lcase(ext) = "htm" Then
  18.             text=gethtml(oFile.Path)
  19.             title=gettitle(text)
  20.             NewName=title & "." & ext
  21.             WSH.echo oFile.Path & " --> " & NewName
  22.             If title <> "" Then
  23.                 If Not fso.FileExists(oFile.ParentFolder.Path & "\" & NewName) Then
  24.                     oFile.Name=NewName
  25.                 Else
  26.                     WSH.echo "文件重名"
  27.                 End If
  28.             End If
  29.         End If
  30.     Next
  31.       
  32.     For Each oSubFolder In oSubFolders
  33.         getfile(oSubFolder.Path)
  34.     Next
  35.     Set oFolder=Nothing
  36.     Set oSubFolders=Nothing
  37. End Function
  38. Function gethtml(ByVal htmlfile)
  39.     htmltext=""
  40.     Set ado=CreateObject("ADODB.Stream")
  41.     ado.Type=2
  42.     '注意html文件的编码,如果是gbk或gb2312,修改下面的"utf-8"为"gb2312"
  43.     ado.Charset="utf-8"
  44.     ado.Open
  45.     ado.LoadFromFile htmlfile
  46.     ado.Position=0
  47.     htmltext=ado.ReadText
  48.     ado.Close
  49.     Set ado=Nothing
  50.     gethtml=htmltext
  51. End Function
  52. Function gettitle(ByVal htmltext)
  53.     htmltitle=""
  54.     Set regex=New RegExp
  55.     regex.Pattern="<title>(.+?)<\/title>"
  56.     regex.IgnoreCase=True
  57.     regex.Global = True
  58.     Set matches=regex.Execute(htmltext)
  59.     If matches.Count = 1 Then
  60.         htmltitle=matches(0).SubMatches(0)
  61.         For i=0 To Ubound(arr)
  62.             htmltitle=replace(htmltitle,arr(i),"_")
  63.         Next
  64.     End If
  65.     Set regex=Nothing
  66.     gettitle=htmltitle
  67. End Function
复制代码
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

返回列表