我正在尝试编写一个 VBS 脚本来从 .ini 文件中删除一行。但是,当我运行它时,新文件(以及备份)被创建并重命名,但我想要删除的行仍然存在?我怎样才能解决这个问题?
这是我的代码:
Const ForReading = 1
Const ForWriting = 2
Const OpenAsASCII = 0
Const CreateIfNotExist = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const OverwriteExisting = True
'Making a backup of the file
objFSO.CopyFile "C:\notes.ini" , "C:\notesBACKUP.ini"
'Setting input of file
strInput = "C:\notes.ini"
Set objInput = objFSO.OpenTextFile(strInput, ForReading)
'Setting temp output for new file with omitted line
strOutput = "C:\notes2.ini"
Set objOutput = objFSO.OpenTextFile(strOutput, _
ForWriting, CreateIfNotExist, OpenAsASCII)
Do Until objInput.AtEndOfStream
strLine = objInput.ReadLine
'Line with EXTMGR to be replaced when copying to new file
If (InStr(LCase(strLine), "EXTMGR") > 0) Then
'New line replacing old one
strLine = "#Deleted"
End If
objOutput.WriteLine strLine
Loop
objInput.Close
objOutput.Close
'Deleting the original file
objFSO.DeleteFile(strInput)
'Renaming the new file (with line removed) to the original filename
objFSO.MoveFile "C:\notes2.ini" , "C:\notes.ini"