批量文件查找替换功能的vbs脚本
批量文件查找替换功能的vbs脚本
发布时间:2016-12-28 来源:查字典编辑
摘要:'============================================'codebylcx修改网上原有的一个小程序,不知...

'============================================

'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"

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新vbs学习
热门vbs学习
脚本专栏子分类