首页 > 编程 > VBScript > 正文

用VBS写的VBSCRIPT代码格式化工具VbsBeautifier

2019-10-26 18:08:03
字体:
来源:转载
供稿:网友

昨天在VBS吧看到一个精华帖《VBS代码格式化工具》,是用C++写的,区区VBS代码格式化,就不要劳C++大驾了吧,用VBS实现VBS代码格式化工具不是更自然么?

网上的VBS代码大部分都没有缩进,新手不知道要缩进,高手缩进了被某些个垃圾网站采集以后也就没有了缩进,还有以一些博客贴吧也会把缩进给吃掉。除了缩进之外,由于学VBS的大部分都是学批处理出身,代码风格还是跟写批处理一样难看。其实一般情况下用VbsEdit 5.2.4.0自带的代码格式化功能就行了,没有必要重复造轮子。只不过VbsEdit 5.2.4.0在格式化带有冒号的代码时不是很理想,加上我已经很久没有写过像样的VBS脚本了,所以还是决定造一下轮子。

2011年12月27日更新:在线VBScript代码格式化工具VbsBeautifier

因为代码比较长,所以贴在文章的最后,下面是VBS代码格式化工具的效果演示:

格式化前的VBS代码:

复制代码 代码如下:

ON ERROR RESUME NEXT:Set fso = CreateObject("Scripting.FileSystemObject"):X=0:T=true:WhiLe T
Input=Inputbox("Filename Lowercase Batch Convertor"&vbcrlf&vbcrlf& _
"Please input the destination folder name. e.g. C:/Webmaster"&vbcrlf&vbcrlf& _
"Note: Do NOT add '/' in the end of folder name!","FLowercase Convertor","C:/")
iF Input="" then:Msgbox"Folder name is empty!",48,"Error!":T=true:else T=false:end If:wend
Msgbox"All files names of "&Input&" will be converted to lowercase now...",64,"Note"
fold(Input):Msgbox"Done! Total "&X&" file(s) were converted to lowercase.",64,"Done"
sub fold(Path):SET f=fso.GetFolder(Path):Set rf = fso.GetFolder(Path).files:Set fc = f.SubFolders
foR EACh fff in rf:lcf1=LCase(fso.GetAbsolutePathName(fff))
fso.MoveFile fff, lcf1:X=X + 1:next:for EacH f1 in fc:fold(f1)
Set file=fso.GetFolder(f1).files:fOR EACh ff iN file:lcf=LCase(fso.GetAbsolutePathName(ff))
fso.MoveFile ff,lcf:NEXT:NEXT:END sub

格式化后的VBS代码:

On Error Resume NextSet fso = CreateObject("Scripting.FileSystemObject")X = 0T = TrueWhile T Input = InputBox("Filename Lowercase Batch Convertor" & vbCrLf & vbCrLf & _ "Please input the destination folder name. e.g. C:/Webmaster" & vbCrLf & vbCrLf & _ "Note: Do NOT add '/' in the end of folder name!","FLowercase Convertor","C:/") If Input = "" Then MsgBox"Folder name is empty!",48,"Error!" T = True Else T = False End IfWEndMsgBox"All files names of " & Input & " will be converted to lowercase now...",64,"Note"fold(Input)MsgBox"Done! Total " & X & " file(s) were converted to lowercase.",64,"Done"Sub fold(Path) Set f = fso.GetFolder(Path) Set rf = fso.GetFolder(Path).files Set fc = f.SubFolders For Each fff In rf lcf1 = LCase(fso.GetAbsolutePathName(fff)) fso.MoveFile fff, lcf1 X = X + 1 Next For Each f1 In fc fold(f1) Set file = fso.GetFolder(f1).files For Each ff In file lcf = LCase(fso.GetAbsolutePathName(ff)) fso.MoveFile ff,lcf Next NextEnd Sub
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表