'============================================
'codebylcx修改网上原有的一个小程序,不知作者,那个程序没有对目录实现递归查找
'将本程序放在你要查找的目录下,或把查找的目录拖到此脚本上,估计还有bug
'=======================================================================================
OnErrorResumenext
DoUntilFalse
Findstr=InputBox("请输入你要查找的字符(串):","请输入")
IfFindstr<>""Then
Exitdo
EndIf
Loop
repwith=InputBox("请输入你要替换的字符(串):,如果留空则只为查找","请输入")
IfWscript.Arguments.Count<>0Then
Fori=0ToWScript.Arguments.Count-1
folderpath=WScript.Arguments(i)
find(folderpath)
Next
Else
'处理当前目录
SetobjShell=CreateObject("WScript.Shell")
folderpath=objShell.CurrentDirectory
find(folderpath)
EndIf
'替换主程序
Subfind(path)
setfso=CreateObject("Scripting.FileSystemObject")
setcurrent=fso.GetFolder(path)
ForEachfileIncurrent.Files
setfsofile=fso.OpenTextFile(file,1,true)
OnErrorResumenext
tempstr=fsofile.Readall
IfInstrRev(tempstr,Findstr,-1,0)<>0Andrepwith=""Then
withFso.opentextfile(left(Wscript.ScriptFullName,len(Wscript.ScriptFullName)-len(Wscript.ScriptName))&"re.txt",8,true)
.writelinefile
.close
endwith
EndIf
Ifrepwith<>""Then
tempstr=replace(tempstr,Findstr,repwith)
setfsofile1=fso.OpenTextFile(file,2,true)
fsofile1.WriteLinetempstr
fsofile.close
Endif
Next
foreachfolderincurrent.subfolders
Callfind(folder.path)
next
setfso=nothing
EndSub
msgbox"OK,查找的文件名保存在re.txt"