我正在尝试编写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"
答案 0 :(得分:2)
您正在对字符串进行LCASE
转换,然后在所有大写字母中查找字符串。
将代码更改为:
If (InStr(strLine, "EXTMGR_ADDINS") > 0)