我正在尝试使用此代码查找未知日期并将其替换为我选择的日期,但它会随着"校准日期\ d {2} - \ d {2} - \ d {继续返回4}未被发现"。我知道使用RegEx将允许我正确地执行此操作,但我不确定如何将其合并到现有代码中?我还没有真正使用RegEx,但我愿意尝试。我对ATLAS非常满意。
' This code replaces one string by another inside files looping though
' subfolders.
' It is vbscript so copy the text below in a .txt file and rename to .vbs
' It will take any non zero bytes file except for extensions you filter
' out in advance.
Option Explicit
Dim objFilesystem, objFolder, objFiles, objFile, tFile, objShell,
objLogFile,objFSO, objStartFolder, colFiles
Dim SubFolder, FileText, bolWriteLog, strLogName, strLogPath, strCount,
strCount2, strOldText, strNewText, strEXT
bolWriteLog = True
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
Set objFilesystem = WScript.CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("wscript.Shell")
strLogName = "dateX.txt"
strLogPath = "C:\Users\e344765\Desktop\Find and replace" & strLogName
strCount = 0
strCount2 = 0
strOldText="calibration date \d{2}-\d{2}-\d{4}"
strNewText="calibration date 01-17-2016"
strEXT = "exe,dll,ps"
ShowSubfolders objFSO.GetFolder(objStartFolder)
Sub ReplaceText(objFile)
strCount = strCount + 1
WriteLog("Opening " & objFile.Name)
Set tFile = objFile.OpenAsTextStream(ForReading, TriStateUseDefault)
FileText = tFile.ReadAll
tFile.Close
If InStr(FileText, strOldText) Then
WriteLog("Replacing " & strOldText & " with " & strNewText & ".")
FileText = Replace(FileText, strOldText, strNewText)
WriteLog("Text replaced")
Else
WriteLog(strOldText & " was not found in the file.")
strCount2 = strCount2 +1
End If
Set tFile = objFile.OpenAsTextStream(ForWriting, TriStateUseDefault)
tFile.Write FileText
tFile.Close
FileText = ""
strCount = 0
strCount2 = 0
End Sub