已經給妳寫好了,但需要傳ptnList.txt文件給妳,直接發到這裏會被規範刪除,妳留個郵箱吧。
貼出其中VBS代碼:
Dim?fso,fd,fl,f,fdpath,findstr,repstr,ul,uOn?Error?Resume?Next
If?WScript.Arguments.Length>=1?Then
fdpath?=?WScript.Arguments(0)Else
fdpath?=?InputBox("請輸入文件夾路徑:","第壹個參數") If?fdpath?=?""?Then?WScript.QuitEnd?Iftmp?=?Split(WScript.ScriptFullName,"\")
tmp(UBound(tmp))?=?"ptnList第章.txt"
usrListPath?=?Join(tmp,"\")
Set?ul?=?ParseJson(GetFile(usrListPath))Set?fso?=?CreateObject("scripting.filesystemobject")
Set?fd?=?fso.GetFolder(fdpath)
Set?fl=fd.Files
For?each?f?in?fl
doreplace?f.PathNext
MsgBox?"替換結束,請查看結果。",,"提示"Function?ParseJson(strJson)
Set?htmlfile?=?CreateObject("htmlfile") Set?owindow?=?htmlfile.parentWindow owindow.execScript?"var?getJson?=?false","javascript" On?Error?Resume?Next?'如果strJson不是json字符串,下面這句會出錯 owindow.execScript?"getJson?=?true;?var?json_obj?=?"?&?strJson,?"javascript" On?Error?Goto?0 If?Not?owindow.getJson?ThenMsgBox?"獲取json失敗,退出vbs",,"tya提示"
ie.Quit
WScript.Quit
End?If Set?ParseJson?=?owindow.json_objEnd?Function?'讀取文件-->替換內容-->保存文件
Function?doreplace(filepath)
Dim?FileName,?Find,?ReplaceWith,?FileContents,?dFileContents,?regEx Set?regEx=New?RegExp?FileName?=?filepath? FileContents?=?GetFile(FileName) For?Each?u?In?ul regEx.Pattern?=?u.ptnregEx.IgnoreCase?=?True
regEx.Global?=?True
ReplaceWith?=u.rep
FileContents?=?regEx.replace(FileContents,ReplaceWith)
Next
WriteFile?FileName,?FileContents
End?Function
'讀取文件?
Function?GetFile(FileName)?
If?FileName<>""?Then? Dim?FS,?FileStream? Set?FS?=?CreateObject("Scripting.FileSystemObject")? On?Error?Resume?Next? Set?FileStream?=?FS.OpenTextFile(FileName)? GetFile?=?FileStream.ReadAll? End?If?End?Function?
'寫文件?
Function?WriteFile(FileName,?Contents)?
Dim?OutStream,?FS? On?Error?Resume?Next? Set?FS?=?CreateObject("Scripting.FileSystemObject")? Set?OutStream?=?FS.OpenTextFile(FileName,?2,?True)? OutStream.Write?Contents?End?Function