English 中文(简体)
VB script + 改为文档(只有“log”名称的档案),并将内容档案复印成一个档案。 txt
原标题:VB script + read files (only files with "log" name) and copy content files into one file.txt
  • 时间:2010-11-11 18:51:42
  •  标签:
  • vbscript

我在C下有以下不同档案:logs3

log1.txt
log2.txt
log3.txt

how to create with VB script , relevant code that create one file called:

log.general.txt 

这份VB文件需要读到名称——标识的日志中的所有档案内容。

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

并将这些档案的内容拷贝到一份档案中——记录、总目录、txt——“也列在记录3下”

<><>>在档案空闲时,须作标记(接下档案)

例如

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

其他例子:(为了解释我的问题)

cat log1.txt >> log.general.txt  
cat log2.txt >> log.general.txt
cat log3.txt >> log.general.txt 
最佳回答

@jon: 这里,VB 文本中的另一种解决办法

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
问题回答

著作载于VB文本:

Set oWSH = CreateObject("WScript.Shell")
oWSH.Run ("%comspec% /c copy /b c:docsconclog*.txt c:docsconconefile.txt")




相关问题
What approach should I use to test a VBScript?

I ve been asked to help out with a project which has made extensive use of VBScript to process a whole bunch of text files and generate certain outputs - sanitized files, SQL entries etc.. The script ...

Unable to call c# code from vbscript - ActiveX error

I am trying to call a method I have written in C# from VBScript. I have followed just about all of the instructions I can find on the web and am still having problems. Specifically I am getting Error:...

How to set delay in vbscript

How to set delay in vbscript? WScript.Sleep(100) does not work on Windows XP, Vista.

Using Classes in a Dictionary in Classic ASP

I usually do C# but have inherited a classic ASP project. I have defined a class: Class clsPayment Public Name End Class Set objPayment = New clsPayment objPayment.Name = "...

How to check which Operating System?

How can I check OS version in a batch file or through a vbs in an Windows 2k/2k3 environment ? You know ... Something like ... : "If winver Win2k then ... or if winver Win2k3 then ....

Problem casting field when querying spreadsheet

I am trying to query an .xls spreadsheet with VBScript, but I have run into an issue when trying to cast a field. I connect to the spreadsheet like this. Set objConnection = CreateObject("ADODB....

热门标签