Vbscript 如何通过搜索旧文件中的特定文本来创建新文件

Vbscript 如何通过搜索旧文件中的特定文本来创建新文件,vbscript,scripting,Vbscript,Scripting,我的旧文件看起来像FolderList.txt,内容如下: \\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20140825\u 123400 \\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20140827\U 065126 \\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20141006\U 09444

我的旧文件看起来像
FolderList.txt
,内容如下:

\\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20140825\u 123400
\\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20140827\U 065126
\\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20141006\U 094447
\\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20141006\U 110546
\\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20141008\U 105947
\\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20150917\U 093710
\\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20151005\U 190254
\\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20151005\U 191124
我想创建一个名为
FolderListNew.txt
的新文件,内容如下:

\\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20141006\u 110546
\\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20141008\U 105947
\\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20150917\U 093710
\\srv10177\temppahir$\Desktop\WORK\6758\Archive\Article\20151005\U 190254
基本上我想搜索2个文本:

Text1 = 20141006_110546
Text2 = 20151005_190254
并从第一次出现的
Text1
一直拉到出现
Text2
为止。 假设数据总是这样,并且按照这些时间戳以升序排序

我尝试了以下脚本,但该脚本无效且不完整:

Option Explicit
Dim objFSO, msg, Filename, file, filestreamOUT, objFile, strContents, strLine, line, Text1, Text2, OLDFilename, tmpStr, MyPos
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Text1 = "20141006_110546"
Text2 = "20151005_190254"
OLDFilename="C:\Users\IBM_ADMIN\Desktop\VB\Folderlist.txt"
WScript.Echo "String to find is : " & Text1
Wscript.Echo "OLDFilename is " & OLDFilename
Set objFile = objFSO.OpenTextFile(OLDFilename, 1)
Wscript.Echo "Reading file the first time:"
strContents = objFile.ReadAll
Wscript.Echo "Line being read is" & strContents

WScript.Echo "tmpStr.ReadLine is : " & Line
'MyPos = InStr (tmpStr.ReadLine, Text1)
WScript.Echo "MyPos value is : " & MyPos
If MyPos >= 0 Then
  'WScript.Echo "Match NOT Found in File and tmpStr.ReadLine is : " & tmpStr.ReadLine
Else 
  WScript.Echo "string value is : " & strLine
  WScript.Echo "Match Found in File and tmpStr.ReadLine is : " & tmpStr.ReadLine
End If

如果要将一个文件中的特定行放入另一个文件,最好逐行读取源文件:

Set inFile = objFSO.OpenTextFile(OLDFilename)
Do Untile inFile.AtEndOfStream
  line = inFile.ReadLine
  ...
Loop
inFile.Close
如果行包含
Text1
,则开始写入输出文件,并在包含
Text2
后停止写入:

Text1 = "20141006_110546"
Text2 = "20151005_190254"

writeOutput = False

Set inFile = objFSO.OpenTextFile("C:\path\to\input.txt")
Set outFile = objFSO.OpenTextFile("C:\path\to\output.txt", 2, True)
Do Until inFile.AtEndOfStream
  line = inFile.ReadLine
  If InStr(line, "20141006_110546") > 0 Then writeOutput = True
  If writeOutput Then outFile.WriteLine line
  If InStr(line, "20151005_190254") > 0 Then Exit Do
Loop
inFile.Close
outFile.Close

如果要将一个文件中的特定行放入另一个文件,最好逐行读取源文件:

Set inFile = objFSO.OpenTextFile(OLDFilename)
Do Untile inFile.AtEndOfStream
  line = inFile.ReadLine
  ...
Loop
inFile.Close
如果行包含
Text1
,则开始写入输出文件,并在包含
Text2
后停止写入:

Text1 = "20141006_110546"
Text2 = "20151005_190254"

writeOutput = False

Set inFile = objFSO.OpenTextFile("C:\path\to\input.txt")
Set outFile = objFSO.OpenTextFile("C:\path\to\output.txt", 2, True)
Do Until inFile.AtEndOfStream
  line = inFile.ReadLine
  If InStr(line, "20141006_110546") > 0 Then writeOutput = True
  If writeOutput Then outFile.WriteLine line
  If InStr(line, "20151005_190254") > 0 Then Exit Do
Loop
inFile.Close
outFile.Close

我是vb脚本新手。我仍然尝试了一些事情,比如..我无法将整个脚本以正确的格式放在这里。。我猜这是VB脚本。如果我错了,请纠正我。@simonalexander2005-我无法将我的脚本以正确的格式放在这里。。我曾经在上面发布过什么,它可读吗?@varocabas-这是VB脚本。从一个星期以来,我一直在尝试自己学习这件事,但直到现在还不能完成这件简单的事情,剧本就从这里开始,还有很长的路要走。所以,任何帮助都会很好,而且会节省很多时间。谢谢好啊下次一定要使用正确的标签。请记住,VB.NET是一个完全不同的故事(例如,它是一种编译语言)。我仍然尝试了一些事情,比如..我无法将整个脚本以正确的格式放在这里。。我猜这是VB脚本。如果我错了,请纠正我。@simonalexander2005-我无法将我的脚本以正确的格式放在这里。。我曾经在上面发布过什么,它可读吗?@varocabas-这是VB脚本。从一个星期以来,我一直在尝试自己学习这件事,但直到现在还不能完成这件简单的事情,剧本就从这里开始,还有很长的路要走。所以,任何帮助都会很好,而且会节省很多时间。谢谢好啊下次一定要使用正确的标签。请记住,VB.NET是一个完全不同的故事(例如,它是一种编译语言)。