本帖最后由 CrLf 于 2012-7-3 12:42 编辑
保存为 test.vbs 或 test.bat 在要处理的目录下运行:- '&start wscript /nologo "/e:vbscript" "%~0"&exit
- Option Explicit
- Dim re,FSO,Dir,file,str,i,a,ar()
- Const ForRead = 1
-
- Set re = New RegExp
- re.Global = True
- re.MultiLine = True
- re.Pattern = "123|124|125|134|135|145|234|235|245|345"
-
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set Dir = FSO.GetFolder(".")
-
- For Each file In Dir.Files
- If file.Type = "文本文档" Then
- ReDim Preserve ar(i)
- ar(i)=file.Name
- i = i + 1
- End If
- Next
-
- If FSO.FolderExists("结果\") = False Then
- FSO.CreateFolder("结果\")
- End If
-
- For Each a In ar
- Call IO(a)
- Next
-
-
- Sub IO(FileIn)
- Dim File,f,ar,a,str,n,filename
-
- filename = FSO.GetBaseName(FileIn)
- Set File = FSO.OpenTextFile(filename & ".txt",ForRead)
- f = File.ReadAll
- File.Close
-
- f = Replace(f," ",vbCrLf)
- Set ar = re.Execute(f)
-
- For Each a In ar
- str = str & a.Value & vbCrLf
- Next
-
- Do
- n = n + 1
- Loop Until FSO.FileExists("结果\" & filename & "_" & n + 1 & ".txt") = False
-
- Set File = FSO.CreateTextFile("结果\" & filename & "_" & n + 1 & ".txt",True)
- File.Write str
- File.Close
- End Sub
复制代码
|