本帖最后由 apang 于 2014-9-11 19:53 编辑
| Dim strPrompt, strInput | | strPrompt = "1.插入空行" & vbLf & "2.删除空行" & vbLf & vbLf & "输入1或2" | | Do while true | | strInput = InputBox(strPrompt, "", "1") | | If IsEmpty(strInput) Then | | WScript.Quit | | ElseIf strInput = "1" or strInput = "2" Then | | Exit Do | | End If | | Loop | | | | Dim fso, file, f, txt | | Set fso = CreateObject("Scripting.FileSystemObject") | | For Each file In fso.GetFolder(".").Files | | If LCase(Right(file, 4)) = ".txt" Then | | Set f = fso.OpenTextFile(file) | | txt = f.ReadAll | | f.Close | | Set f = Nothing | | If strInput = "1" Then | | txt = RegEx(txt, "\r\n", "$&$&") | | Else | | txt = RegEx(txt & vbCrLf, "(\s*\n)+", vbCrLf) | | If Left(txt, 2) = vbCrLf Then txt = Mid(txt, 3) | | End If | | fso.OpenTextFile(file, 2).Write txt | | End If | | Next | | | | MsgBox "OK" | | | | Function RegEx(s, pattern, s1) | | Dim re | | Set re = New RegExp | | re.Pattern = pattern | | re.Global = true | | RegEx = re.Replace(s, s1) | | End FunctionCOPY |
|