Use vbscript script to modify the file content, which is applicable to automated operations.
'Create a Replace. vbs script. The script content is as follows. When the program is running, enter three parameters: search content, Replace content, and file
Copy codeThe Code is as follows: Dim FileName, Find, ReplaceWith, FileContents, dFileContents
Find = WScript. Arguments (0)
ReplaceWith = WScript. Arguments (1)
FileName = WScript. Arguments (2)
'Reading files
FileContents = GetFile (FileName)
'Replace all "search content" in the file with "replace content"
DFileContents = replace (FileContents, Find, ReplaceWith, 1,-1, 1)
'Compare the source file with the replaced File
If dFileContents <> FileContents Then
'Save the replaced File
WriteFile FileName, dFileContents
Wscript. Echo "Replace done ."
If Len (ReplaceWith) <> Len (Find) Then
'Calculates the total number of replacements.
Wscript. Echo _
(Len (dFileContents)-Len (FileContents)/(Len (ReplaceWith)-Len (Find )))&_
"Replacements ."
End If
Else
Wscript. Echo "Searched string Not In the source file"
End If
'Reading files
Function GetFile (FileName)
If FileName <> "" Then
Dim FS, FileStream
Set FS = CreateObject ("Scripting. FileSystemObject ")
On error resume Next
Set FileStream = FS. OpenTextFile (FileName)
GetFile = FileStream. ReadAll
End If
End Function
'Write a file
Function WriteFile (FileName, Contents)
Dim OutStream, FS
On error resume Next
Set FS = CreateObject ("Scripting. FileSystemObject ")
Set OutStream = FS. OpenTextFile (FileName, 2, True)
OutStream. Write Contents
End Function