VBS脚本,中间用到了遍历文件夹,正则匹配。使用了 WScript.Shell 对象的几个方法。

本文主要是介绍VBS脚本,中间用到了遍历文件夹,正则匹配。使用了 WScript.Shell 对象的几个方法。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这个脚本只满足了我要完成的工作的一部分内容,其余内容必须在公司才能完成及调试了。


脚本运行需要有如下条件:

与脚本在同一级目录下的 ctags.exe ,需要5.8以后版本的。主要是要支持正则,支持 - R选项后面带目录路径的。

同一级目录下要有logic文件夹,文件夹内要有符合语法的logic文件。


脚本如下:

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 初始化一些全局变量
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim FSO
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 展示逻辑的方式
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const SW_LOGIC_IN_DLG = 0
Const INSERT_LOGIC_TO_SCRIPT = 1
Const OPEN_LOGIC_FILE = 2''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Window Style
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const SW_HIDE = 0
Const SW_SHOW = 1
Const SW_MIN = 2
Const SW_MAX = 3''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 由 Drive.DriveType 返回的常数
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const DriveTypeRemovable = 1
Const DriveTypeFixed = 2
Const DriveTypeNetwork = 3
Const DriveTypeCDROM = 4
Const DriveTypeRAMDisk = 5''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 由 File.Attributes 返回的常数
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const FileAttrNormal  = 0
Const FileAttrReadOnly = 1
Const FileAttrHidden = 2
Const FileAttrSystem = 4
Const FileAttrVolume = 8
Const FileAttrDirectory = 16
Const FileAttrArchive = 32 
Const FileAttrAlias = 64
Const FileAttrCompressed = 128''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 用来打开文件的常数
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const OpenFileForReading = 1 
Const OpenFileForWriting = 2 
Const OpenFileForAppending = 8 Function GenerateFileInformation(File)Dim SS = NewLine & "Path:" & TabStop & File.PathS = S & NewLine & "Name:" & TabStop & File.NameS = S & NewLine & "Type:" & TabStop & File.TypeS = S & NewLine & "Attribs:" & TabStop & ShowFileAttr(File)S = S & NewLine & "Created:" & TabStop & File.DateCreatedS = S & NewLine & "Accessed:" & TabStop & File.DateLastAccessedS = S & NewLine & "Modified:" & TabStop & File.DateLastModifiedS = S & NewLine & "Size" & TabStop & File.Size & NewLineGenerateFileInformation = SEnd FunctionFunction GetFolderLastModifyTime (FolderPath)If (FSO.FileExists("tags")) ThenSet File = FSO.GetFile("tags")lastModTime = File.DateLastModified'MsgBox lastModTimeElsemsg = filespec & " doesn't exist."'MsgBox msgEnd IfSet Folder = FSO.GetFolder(FolderPath)folderModTime = Folder.DateLastModifiedlTime = Folder.DateLastModifiedSet Files = Folder.FilesFor Each File In FilesIf lTime < File.DateLastModified ThenlTime = File.DateLastModifiedEnd IfNextGetFolderLastModifyTime = lTime
End FunctionFunction FlashTagFile (tagFileName, FolderPath)If (FSO.FileExists(tagFileName)) ThenSet File = FSO.GetFile(tagFileName)lastModTime = File.DateLastModifiedElsestrCmd = "ctags.exe --langdef=logic --langmap=logic:.logic --regex-logic=""/^\s*(Logic|Join)\s+(\w+)\s+\{/\2/L,Logic/"" -n -R " & FolderPathoExec = WshShell.Run(strCmd, SW_HIDE, True)FlashTagFile = TrueExit FunctionEnd IfIf lastModTime < GetFolderLastModifyTime(FolderPath) ThenstrCmd = "ctags.exe --langdef=logic --langmap=logic:.logic --regex-logic=""/^\s*(Logic|Join)\s+(\w+)\s+\{/\2/L,Logic/"" -n -R " & FolderPathoExec = WshShell.Run(strCmd, SW_HIDE, True)FlashTagFile = True        ElseFlashTagFile = FalseEnd IfEnd FunctionFunction LocationLogic (logicName, logicFileName, lineNum)LocationLogic = "It's just a empty Function now!" & vbCrLf _& "It will find [" & logicName & "] in file [" & logicFileName & "]. line : " & lineNumEnd FunctionFunction GetLogicInfo (logicName, tagFileName)Dim oRe, oMatch, oMatchesSet tagFile = FSO.GetFile(tagFileName)Set TextStream = FSO.OpenTextFile(tagFileName, OpenFileForReading)allLogicInfo = TextStream.ReadAllTextStream.Close' the format as below'testLogic010	logic\Logic0.logic	24;"	LSet oRe = New RegExpoRe.Pattern = logicName & "\s+(.*?)\s+(\d+);""\s+(\w)"' 得到 Matches 集合oRe.IgnoreCase = False   ' 设置是否区分大小写。oRe.Global = False   ' 设置全程匹配。Set oMatches = oRe.Execute(allLogicInfo)If oMatches.Count = 0 ThenMsgBox "Can not find this logic <" & logicName & ">"GetLogicInfo = ""Exit FunctionElse        Set oMatch = oMatches(0)filePath = oMatch.SubMatches(0)lineNum = oMatch.SubMatches(1)End IfGetLogicInfo = LocationLogic(logicName, filePath, lineNum)Set oRe = NothingEnd FunctionFunction GetLogicNameFromGTR ()' It is empty nowGetLogicNameFromGTR = "testLogic99956"End FunctionFunction GetLogicFilePath ()' 这种方式能够读取的注册表有限制,功能更强的方式是采用winmgmts对象读取,但是没有这个简单GetLogicFilePath = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Evernote\Installer")GetLogicFilePath = "logic"End FunctionFunction InsertLogicInfoToScript (logicInfo)' It is empty nowInsertLogicInfoToScript = "It is empty now"End FunctionFunction OpenLogicFileInGTR ()' 查找逻辑文件及逻辑所在行数的方法与函数GetLogicInfo一样InsertLogicInfoToScript = "It is empty now"End FunctionFunction Main ()Set   objArgs   =   WScript.ArgumentsIf objArgs.Count > 0 ThenshowMethod = objArgs(I)End IflogicName = GetLogicNameFromGTR()FlashTagFile "tags", GetLogicFilePath()logicInfo = GetLogicInfo(logicName, "tags")Select Case showMethod' 64 means show "Information Mark" icon.'Case SW_LOGIC_IN_DLG     WshShell.popup(logicInfo, 10, "逻辑提示,10秒后消失", 64)Case INSERT_LOGIC_TO_SCRIPT   InsertLogicInfoToScript logicInfoCase OPEN_LOGIC_FILE    OpenLogicFileInGTRCase Else  WshShell.popup logicInfo, 10, "逻辑提示,10秒后消失", 64End Select
End FunctionStartTime = Timer
Main
EndTime = Timer
TimeIt = EndTime - StartTime
MsgBox "cast time " & TimeIt


这篇关于VBS脚本,中间用到了遍历文件夹,正则匹配。使用了 WScript.Shell 对象的几个方法。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/680053

相关文章

Spring Security自定义身份认证的实现方法

《SpringSecurity自定义身份认证的实现方法》:本文主要介绍SpringSecurity自定义身份认证的实现方法,下面对SpringSecurity的这三种自定义身份认证进行详细讲解,... 目录1.内存身份认证(1)创建配置类(2)验证内存身份认证2.JDBC身份认证(1)数据准备 (2)配置依

Java Spring 中 @PostConstruct 注解使用原理及常见场景

《JavaSpring中@PostConstruct注解使用原理及常见场景》在JavaSpring中,@PostConstruct注解是一个非常实用的功能,它允许开发者在Spring容器完全初... 目录一、@PostConstruct 注解概述二、@PostConstruct 注解的基本使用2.1 基本代

C#使用StackExchange.Redis实现分布式锁的两种方式介绍

《C#使用StackExchange.Redis实现分布式锁的两种方式介绍》分布式锁在集群的架构中发挥着重要的作用,:本文主要介绍C#使用StackExchange.Redis实现分布式锁的... 目录自定义分布式锁获取锁释放锁自动续期StackExchange.Redis分布式锁获取锁释放锁自动续期分布式

springboot使用Scheduling实现动态增删启停定时任务教程

《springboot使用Scheduling实现动态增删启停定时任务教程》:本文主要介绍springboot使用Scheduling实现动态增删启停定时任务教程,具有很好的参考价值,希望对大家有... 目录1、配置定时任务需要的线程池2、创建ScheduledFuture的包装类3、注册定时任务,增加、删

使用Python实现矢量路径的压缩、解压与可视化

《使用Python实现矢量路径的压缩、解压与可视化》在图形设计和Web开发中,矢量路径数据的高效存储与传输至关重要,本文将通过一个Python示例,展示如何将复杂的矢量路径命令序列压缩为JSON格式,... 目录引言核心功能概述1. 路径命令解析2. 路径数据压缩3. 路径数据解压4. 可视化代码实现详解1

python获取网页表格的多种方法汇总

《python获取网页表格的多种方法汇总》我们在网页上看到很多的表格,如果要获取里面的数据或者转化成其他格式,就需要将表格获取下来并进行整理,在Python中,获取网页表格的方法有多种,下面就跟随小编... 目录1. 使用Pandas的read_html2. 使用BeautifulSoup和pandas3.

Pandas透视表(Pivot Table)的具体使用

《Pandas透视表(PivotTable)的具体使用》透视表用于在数据分析和处理过程中进行数据重塑和汇总,本文就来介绍一下Pandas透视表(PivotTable)的具体使用,感兴趣的可以了解一下... 目录前言什么是透视表?使用步骤1. 引入必要的库2. 读取数据3. 创建透视表4. 查看透视表总结前言

Python 交互式可视化的利器Bokeh的使用

《Python交互式可视化的利器Bokeh的使用》Bokeh是一个专注于Web端交互式数据可视化的Python库,本文主要介绍了Python交互式可视化的利器Bokeh的使用,具有一定的参考价值,感... 目录1. Bokeh 简介1.1 为什么选择 Bokeh1.2 安装与环境配置2. Bokeh 基础2

Android使用ImageView.ScaleType实现图片的缩放与裁剪功能

《Android使用ImageView.ScaleType实现图片的缩放与裁剪功能》ImageView是最常用的控件之一,它用于展示各种类型的图片,为了能够根据需求调整图片的显示效果,Android提... 目录什么是 ImageView.ScaleType?FIT_XYFIT_STARTFIT_CENTE

Spring 中的循环引用问题解决方法

《Spring中的循环引用问题解决方法》:本文主要介绍Spring中的循环引用问题解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录什么是循环引用?循环依赖三级缓存解决循环依赖二级缓存三级缓存本章来聊聊Spring 中的循环引用问题该如何解决。这里聊