aletri
Goto Top

Vbscript bestimmte Zeile ungeachtet der Nummerierung löschen

Guten Tag an alle

Mit folgendem Script lässt sich eine bestimmte Zeile nämlich: "SimObjectPaths.6=Addon Scenery\Europe\Italy\Ancona\simobjects" löschen.
Die "SimObjectPaths.X=Addon....." ist aber nicht eine fixe Zahl sondern X beliebig (numerierung)!!
Wie muss der Script angepasst werden?

Hier der Script
Dim objShell,appdata
Set objShell = CreateObject("wscript.shell")  
appdata = objShell.ExpandEnvironmentStrings("%appdata%")  

strFileName = (appdata & "\Microsoft\FSX\fsx.cfg")  

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")  
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)

Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    If InStr(strLine, "SimObjectPaths.X=Addon Scenery\Europe\Italy\Ancona\simobjects") = 0 Then  
        strNewContents = strNewContents & strLine & vbCrLf
    End If
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.Write strNewContents

objFile.Close 
a.Close 

Set fs = Nothing 


Besten Dank für Hilfe

Content-Key: 318031

Url: https://administrator.de/contentid/318031

Printed on: April 24, 2024 at 13:04 o'clock

Mitglied: 131026
131026 Oct 16, 2016 updated at 16:29:47 (UTC)
Goto Top
Dim objShell,appdata
Set objShell = CreateObject("wscript.shell")  
appdata = objShell.ExpandEnvironmentStrings("%appdata%")  

strFileName = (appdata & "\Microsoft\FSX\fsx.cfg")  

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")  
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
Set regex = CreateObject("vbscript.regexp")  
regex.IgnoreCase = True
regex.Pattern = "SimObjectPaths\.\d+=Addon Scenery\\Europe\\Italy\\Ancona\\simobjects"  

Do Until objFile.AtEndOfStream
    strLine = objFile.ReadLine
    If regex.Test(strLine) = False Then
        strNewContents = strNewContents & strLine & vbCrLf
    End If
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.Write strNewContents

objFile.Close
Set fs = Nothing 
Mit Powershell wäre es aber viel viel kürzer :-P
(gc "$env:appdata\Microsoft\FSX\fsx.cfg") | ?{$_ -notmatch 'SimObjectPaths\.\d+=Addon Scenery\\Europe\\Italy\\Ancona\\simobjects'} | set-content "$env:appdata\Microsoft\FSX\fsx.cfg"  
R.
Member: aletri
aletri Oct 16, 2016 at 16:22:47 (UTC)
Goto Top
Hallo ranger
Tausend Dank !
Krieg beim Ausführen des Scripts folgende Fehlermeldung:

Line: 29
Char: 1
Error: Object required: 'a'
Code: 800A01A8

habe ich was falsch gemacht?
Mitglied: 131026
Solution 131026 Oct 16, 2016 updated at 16:30:59 (UTC)
Goto Top
Den Code hatte ich nur von dir oben kopiert und ergänzt ... der ist auf deinem eigenen Mist gewachsen.

Also Zeile raus nehmen weil a ja sowieso keine Referenz hat :-P
Member: aletri
aletri Oct 16, 2016 at 16:32:48 (UTC)
Goto Top
hatte ich eben auch gemacht und es hat geklappt!!

Besten Dank nochmals und schönen Abend