华域联盟 vbs 批量文件查找替换功能的vbs脚本

批量文件查找替换功能的vbs脚本

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

'code by lcx 修改网上原有的一个小程序,不知作者,那个程序没有对目录实现递归查找

'将本程序放在你要查找的目录下,或把查找的目录拖到此脚本上,估计还有bug

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

On Error Resume next

Do Until False

        Findstr=InputBox("请输入你要查找的字符(串):", "请输入")

        If Findstr <> "" Then

                Exit do

        End If

Loop

repwith=InputBox("请输入你要替换的字符(串):,如果留空则只为查找", "请输入")

If Wscript.Arguments.Count <> 0 Then

        For i=0 To WScript.Arguments.Count-1

                folderpath=WScript.Arguments(i)

                find(folderpath)

        Next

Else

        '处理当前目录

        Set objShell = CreateObject("WScript.Shell")

        folderpath=objShell.CurrentDirectory

        find(folderpath)

End If

'替换主程序

Sub find(path)

        set fso=CreateObject("Scripting.FileSystemObject")

        set current=fso.GetFolder(path)

        For Each file In current.Files

                        set fsofile=fso.OpenTextFile(file, 1, true)

       On Error Resume next

                        tempstr=fsofile.Readall

       If InstrRev(tempstr,Findstr, -1, 0)<>0 And repwith = "" Then 

       with Fso.opentextfile(left(Wscript.ScriptFullName,len(Wscript.ScriptFullName)-len(Wscript.ScriptName))&"\re.txt",8,true)

                        .writeline file

       .close

       end with

       End If

       If repwith <> "" Then

       tempstr=replace(tempstr, Findstr, repwith)

       set fsofile1=fso.OpenTextFile(file, 2, true)

                        fsofile1.WriteLine tempstr

       fsofile.close

       End if

                       

        Next

   for each folder in current.subfolders 

   Call find(folder.path)

   next

set fso=nothing

End Sub

msgbox "OK,查找的文件名保存在re.txt"

本文由 华域联盟 原创撰写:华域联盟 » 批量文件查找替换功能的vbs脚本

转载请保留出处和原文链接:https://www.cnhackhy.com/15046.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部