zoukankan      html  css  js  c++  java
  • 自定义VBS脚本(统计在指定文件中搜索字符串出现的次数)

    '==========================================================================
    '
    ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.1
    '
    ' NAME:
    '
    ' AUTHOR: Windows 用户 , AEBELL
    ' DATE : 2014/7/7
    '
    ' COMMENT:
    '
    '==========================================================================
    '函数一,复制指定文件到指定目录下。

    Set fso=CreateObject("Scripting.filesystemobject")

    Function CopyFileToPath()

    SrcPATH = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
    DstPATH = "C:Program FilesAEBELL_DebugToolDebugTooldllFigClient"

    fso.CopyFile SrcPATH&""&"FigClient.exe",DstPATH,True

    End Function

    ' 'Call CopyFileToPath()

    '=========================================================================
    '函数二,搜索指定字符串在指定文件中出现的次数,并将统计出来的次数写到一个Log文件中.
    '通过inpubox函数来输入路径来实现

    Function SerachFileStr()

    SelectFile=InputBox("请输入要搜索文件的存放的完整路径?","提示")

    SerachStr=InputBox("请输入要搜索的字符串","提示")

    '用split函数在输入的路径中取到文件名
    SplitStrArray=Split(SelectFile,"")
    ArrayCount=UBound(Split(SelectFile,""))

    FileName=SplitStrArray(ArrayCount)

    Set OpenFile=fso.OpenTextFile(SelectFile,1)
    AllContent=OpenFile.ReadAll()

    Set re=New RegExp
    re.Pattern=SerachStr
    re.Global=True
    re.IgnoreCase=True
    Set matches=re.Execute(AllContent)
    SerachCount=matches.Count

    MsgBox "要搜索的字符串"&re.Pattern&"在"&FileName&"文件中出现的次数为:"&SerachCount&" 次",,"系统提示"
    Set NewOpen=fso.CreateTextFile("c:log.txt")
    NewOpen.WriteLine("要搜索的字符串"&re.Pattern&"在"&FileName&"文件中出现的次数为:"&SerachCount&" 次")

    End Function

    ' SerachFileStr()

    '=========================================================================
    '函数三,搜索指定字符串在指定文件中出现的次数,并将统计出来的次数写到一个Log文件中.
    '通过调用系统对话框来选择文件的方式来实现

    Function CallSystemDlgSelFile()

    PATH=BrowseForFile()

    SplitStrArray=Split(PATH,"")
    ArrayCount=UBound(Split(PATH,""))
    FileName=SplitStrArray(ArrayCount)

    Set OpenFile=fso.OpenTextFile(PATH,1)
    AllContent=OpenFile.ReadAll()


    SerachStr=InputBox("请输入要搜索的字符串","提示")

    Set re=New RegExp
    re.Pattern=SerachStr
    re.Global=True
    re.IgnoreCase=True
    Set matches=re.Execute(AllContent)
    SerachCount=matches.Count

    MsgBox "要搜索的字符串"&re.Pattern&"在"&FileName&"文件中出现的次数为:"&SerachCount&" 次",,"系统提示"
    Set NewOpen=fso.CreateTextFile("c:log.txt")
    NewOpen.WriteLine("要搜索的字符串"&re.Pattern&"在"&FileName&"文件中出现的次数为:"&SerachCount&" 次")

    End Function

    CallSystemDlgSelFile()

    '=======================================================================
    '函数四,在windows 7上调用系统对话框,来选择文件
    Function BrowseForFile()
    Set shell = CreateObject("WScript.Shell")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set tempFolder = fso.GetSpecialFolder(2)
    tempName = fso.GetTempName()
    Set tempFile = tempFolder.CreateTextFile(tempName & ".hta")
    tempFile.Write _
    "<html>" & _
    "<head>" & _
    "<title>Browse</title>" & _
    "</head>" & _
    "<body>" & _
    "<input type='file' id='f' />" & _
    "<script type='text/javascript'>" & _
    "var f = document.getElementById('f');" & _
    "f.click();" & _
    "var shell = new ActiveXObject('WScript.Shell');" & _
    "shell.RegWrite('HKEY_CURRENT_USER\Volatile Environment\MsgResp', f.value);" & _
    "window.close();" & _
    "</script>" & _
    "</body>" & _
    "</html>"
    tempFile.Close
    shell.Run tempFolder & "" & tempName & ".hta", 0, True
    BrowseForFile = shell.RegRead("HKEY_CURRENT_USERVolatile EnvironmentMsgResp")
    shell.RegDelete "HKEY_CURRENT_USERVolatile EnvironmentMsgResp"
    End Function

    ' path = BrowseForFile()
    ' If path <> "" Then
    ' MsgBox path
    ' End If

    '==============================================================================
    '函数五,打印ping命令,并显示时间

    Function PrintPingTime()

    Set shell = WScript.CreateObject("WScript.Shell")
    Set re=New RegExp

    re.Pattern = "^Reply|^Request"
    Set myping=shell.Exec("ping -t 192.168.18.128")
    while Not myping.StdOut.AtEndOfStream
    strLine = myping.StdOut.ReadLine()

    WScript.Echo Date & " "& Time & chr(9) & strLine
    Wend

    End Function

    ' PrintPingTime()

  • 相关阅读:
    numpy中linspace用法 (等差数列创建函数)
    Ubuntu环境下 matplotlib 图例中文乱码
    转载: 广义逆矩阵
    matplotlib.pyplot中add_subplot方法参数111的含义
    转载:(论文) 二次指数平滑法中确定初始值的简便方法
    图像处理之 opencv 学习---opencv 中的常用算法
    图像处理之 opencv 学习---矩阵的操作
    编译异常之static和extern---more than one storage class specified
    格式转换至yuv422转 yuv420
    阶段3 3.SpringMVC·_02.参数绑定及自定义类型转换_6 自定义类型转换器代码编写
  • 原文地址:https://www.cnblogs.com/jinjiangongzuoshi/p/3844625.html
Copyright © 2011-2022 走看看