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

Ausgedruckt am: 19.03.2024 um 09:03 Uhr

Mitglied: 131026
131026 16.10.2016 aktualisiert um 18:29:47 Uhr
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.
Mitglied: aletri
aletri 16.10.2016 um 18:22:47 Uhr
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
Lösung 131026 16.10.2016 aktualisiert um 18:30:59 Uhr
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
Mitglied: aletri
aletri 16.10.2016 um 18:32:48 Uhr
Goto Top
hatte ich eben auch gemacht und es hat geklappt!!

Besten Dank nochmals und schönen Abend