如何在输出文本之间添加一行?

时间:2019-02-03 15:26:27

标签: vbscript

下一个标题将替换同一行上的上一个标题。结果,只有最后一个标题最终将保留在文本文件中。

我下面的VBScript将找到许多更新标题(脚本中的=“ Title”)。每个“标题”将显示在输出文件“ c:\ Testing \ testing.txt”中。一个标题将一次显示在第一行。命令“下一个”将显示下一个标题,当前一个标题消失时,该标题将显示在同一行上。简而言之,下一个标题将替换第一行中的上一个标题。结果,只有最后一个标题最终将保留在文件中。是否可以在两个标题之间添加一个空行,以便所有标题都显示在文件中?

Set Job = CreateObject("Microsoft.Update.Session")
Set Tool = Job.CreateupdateSearcher() 
Set Result = Tool.Search("IsInstalled=0 and IsHidden=0")
For Number = 0 To Result.Updates.Count-1
    Set Title = Result.Updates.Item(Number)

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    outFile = "c:\Testing\testing.txt"
    Set objFile = objFSO.CreateTextFile(outFile, True)
    objFile.Write Title & vbCrLf 
    objFile.Close
Next

我希望标题显示在不同的行而不是同一行。

2 个答案:

答案 0 :(得分:0)

我刚刚发现,在以下脚本中, OpenTextFile 8,True 都不需要,

Set Job = CreateObject("Microsoft.Update.Session")
Set Tool = Job.CreateupdateSearcher() 
Set Result = Tool.Search("IsInstalled=0 and IsHidden=0")
Set X = CreateObject("Scripting.FileSystemObject")
Set Z = X.CreateTextFile("Updates_found.txt")

For Number = 0 To Result.Updates.Count-1
Set Title = Result.Updates.Item(Number)
Z.Writeline Title
Next

答案 1 :(得分:-1)

Set objFSO  = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("c:\Testing\testing.txt", True)  'True = overwrite existing file
objFile.Close
Set objFile = objFSO.OpenTextFile("c:\Testing\testing.txt", 8)       '8 = For Appending
objFile.WriteLine ("Title")
objFile.WriteLine ("Title2")
objFile.Close

希望这会有所帮助!