'==========================================================================
'
' 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()
技术改变世界! --狂诗绝剑