我在C:\ logs3
下有以下不同的文件log1.txt
log2.txt
log3.txt
如何使用VB脚本创建相关代码,创建一个名为:
的文件log.general.txt
这个VB脚本需要读取log3目录下名为-log
的所有文件内容as: log1.txt log2.test.txt log3.start.txt mylog.txt big.log.txt
But: not read the files as: test.txt or ABBA.txt or CAR.txt
将这些文件的内容复制到一个文件--log.general.txt - “也在log3目录下”
* 备注,如果文件为空,则需要转义(继续下一个文件)
例如
log1.txt:
111111
222222
log2.txt:
333333
444444
log3.txt
555555
666666
file.test.txt
777777
888888
log.general.txt content: -> (Expected results from the VB script)
111111
222222
333333
444444
555555
666666
来自linux的其他例子:(为了解释我的问题)
cat log1.txt >> log.general.txt
cat log2.txt >> log.general.txt
cat log3.txt >> log.general.txt
答案 0 :(得分:1)
@jon:这是VBScript中的另一个解决方案
Option Explicit
Const ForAppending = 8
Const ForReading = 1
Const ForWriting = 2
Dim oFS, oFolder, oFile, oRead, oWrite, oRegEx
Dim sContents, sDir, sFile
Dim iMatch
sDir = "C:\log3\"
sFile = "log.general.txt"
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFS.GetFolder(sDir)
Set oRegEx = New RegExp
With oRegEx
.Pattern = "log"
.IgnoreCase = True
.Global = True
End With
For Each oFile In oFolder.Files
iMatch = oRegex.Test(oFile.Name)
If oFile.Name <> sFile AND iMatch = -1 Then
Set oRead = oFS.OpenTextFile(oFile, ForReading)
sContents = sContents & oRead.ReadAll & vbCrLf
oRead.Close
End If
Next
Set oWrite = oFS.OpenTextFile(sDir & sFile, ForAppending, True)
oWrite.WriteLine sContents
oWrite.Close
Set oRegEx = Nothing
Set oFS = Nothing
答案 1 :(得分:0)
这适用于VBScript:
Set oWSH = CreateObject("WScript.Shell")
oWSH.Run ("%comspec% /c copy /b c:\docs\conc\log*.txt c:\docs\conc\onefile.txt")