自定义VBS脚本(统计在指定文件中搜索字符串出现的次数)
2014-07-15 13:49
453 查看
'==========================================================================
'
' 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 Files\AEBELL_DebugTool\DebugTool\dll\FigClient\"
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_USER\Volatile Environment\MsgResp")
shell.RegDelete "HKEY_CURRENT_USER\Volatile Environment\MsgResp"
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()
'
' 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 Files\AEBELL_DebugTool\DebugTool\dll\FigClient\"
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_USER\Volatile Environment\MsgResp")
shell.RegDelete "HKEY_CURRENT_USER\Volatile Environment\MsgResp"
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()
相关文章推荐
- 使用Linux命令统计文件指定列中字符串出现次数
- python统计指定文件中指定字符或字符串出现的次数
- linux统计文件中字符串出现次数
- 统计一个给定字符串中指定的字符出现的次数
- 统计一文件中出现给定字符串的次数
- python统计字符串中指定字符出现次数的方法
- 嵌入式 shell用一行命令统计一文本文件中包含指定字符串出现次数
- java统计字符串中指定元素出现次数方法
- 利用shell脚本统计文件中出现次数最多的IP
- shell统计文件里面特定字符串出现次数
- 指定文件中查找一个字符串并显示该字符串出现的次数
- 【Shell】统计文件里面特定字符串出现次数
- VBS去除字符串的重复项并统计重复字符出现的次数
- 统计一个字符串在文件中出现的次数
- Shell 统计文件里面特定字符串出现次数
- 统计文件中出现字符串的次数(中,英)
- 统计一个给定字符串中指定的字符出现的次数
- 统计某个字符串中指定字符串出现的次数
- 读取txt文件统计文章里"java"字符串出现的次数
- python脚本:搜索某一目录下出现特定字符串的文件