//变量定义 Dim objDialog, fso Dim fSourceName,fTargetname Dim sLine, s, stemp1,stemp2 Dim LineLenOld, LineLenNew Dim MyArray, i1, i, s1 Dim DirPath //变量初始化 ForReading = 1:ForWriting = 2:ForAppending=8 remColor="Green" explainColor="Blue" IniFileName="c:\path.ini" //============== 主程序 =============== Gosub 读取路径 Gosub 打开文件 Rem 结束 MessageBox "程序结束, 谢谢使用" EndScript //============== 子程序 =============== Sub 打开文件 Set objDialog = CreateObject("UserAccounts.CommonDialog") objDialog.Filter = "脚本文件|*.txt" objDialog.InitialDir = DirPath intResult = objDialog.ShowOpen If intResult <> 0 Gosub 保存路径 Gosub 改名 Gosub 格式编辑 Else Goto 结束 EndIf Return 打开文件 Sub 保存路径 sTemp2 = objDialog.FileName MyArray = Split(sTemp2,"\",-1,1) i = UBound(MyArray) i1 = 1 s1 = MyArray(0) While i1<i s1 = s1 & "\" & MyArray(i1) i1 = i1+1 EndWhile s1 = s1 & "\" Plugin File.WriteINI("setup","路径",s1,IniFileName) Return 保存路径 Sub 读取路径 DirPath = "c:\" Plugin DirPath = File.ReadINI("setup","路径",IniFileName) Return 读取路径 Sub 改名 fSourceName = objDialog.FileName fTargetName = Replace(fSourceName,".txt",".ini") Return 改名 Sub 格式编辑 Set fso = CreateObject("Scripting.FileSystemObject") Set fSource = fso.OpenTextFile(fSourceName, ForReading, True) Set fTarget = fso.OpenTextFile(fTargetName, ForWriting, True) While fSource.AtEndOfStream<>true sLine = fSource.ReadLine() lineLenOld = Len(sLine) s=Trim(sLine) lineLenNew = Len(s) sTemp1 = Left(s,2) sTemp2 = Right(s,Len(s)-2) If s="[General]" s="[color=" & explainColor & "]" & s ElseIf s="[Script]" s="[/color][color=" & explainColor & "]" & s & "[/color]" ElseIf sTemp1="//" s="[color=" & remColor & "]" &s &"[/color]" Else EndIf s = Space(lineLenOld-lineLenNew) & s fTarget.WriteLine(s) EndWhile fSource.Close fTarget.Close VBSCall RunApp(fTargetName) Return 格式编辑