expire.txt文件包含197.015行。
foo1; 2020-03-01 13:33;
foo2; 2020-02-01 08:45;
foo3; 2020-01-01 11:30;
...
...
...
在这个大的 txt 文件中,我需要从以下位置替换所有日期值:
- 2020-03-01 13:33至2020-03-01
- 2020-02-01 08:45至2020-02-01
- 2020-01-01 11:30至2020-01-01
- ...
- ...
- 2018-01-01 12:40到2018-01-01(这是最后一行197.015)
我已经尝试了下面的代码。
没有错误,但 txt 文件中的替换输入不起作用。
新的expire.txt文件保持不变。
如何解决这个问题?
Const ForReading = 1
Const ForWriting = 2
intCount = 0
intIndex = 1
Set oFSO = CreateObject("Scripting.FileSystemObject")
str_input = ""
Set oInFile = oFSO.OpenTextFile("expiration.txt", 1)
str_input = oInFile.ReadAll()
Set oRegEx = CreateObject("VBScript.RegExp")
With oRegEx
.Multiline = True
.Global = True
.Pattern = "(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+);"
End With
Do Until oInFile.AtEndOfStream
str_input = oInFile.ReadLine
If (intCount = 0) Then
str_input = oRegEx.Replace(str_input, "$1-$2-$3;")
Set oInFile = oFSO.OpenTextFile("expiration.txt", 2)
oInFile.Write str_input
oInFile.Close
End If
intCount = intCount + 1
If (intCount = 200) Then
intCount = 0
intIndex = intIndex + 1
oInFile.Close
End If
Loop
oInFile.Close
set oFSO = nothing
WScript.echo "ok"