"Don't worry, about a thing, Cause every little thing is gonna be alright"
Je boedoelt dat je een tekst file wil bewerken met find & replace?
Je zou dat denk ik beter via Vbscript of Powershell kunnnen doen.
Je zou dat denk ik beter via Vbscript of Powershell kunnnen doen.
The best thing about UDP jokes is that I don't care if you get them or not.
Hier staan wat voorbeelden van een Bat file en VBS:
http://stackoverflow.com/...nd-edit-lines-in-txt-file
http://stackoverflow.com/...nd-edit-lines-in-txt-file
pff, met enkel batch is dat best lastig.
Je kunt regels zoeken mbv 'type [bestandsnaam] | find "zoekterm" ', maar voor iets serieuzer werk zou ik op zoek gaan naar iets dat commandline regexps voor je kan uitvoeren op een bestand..
Je kunt regels zoeken mbv 'type [bestandsnaam] | find "zoekterm" ', maar voor iets serieuzer werk zou ik op zoek gaan naar iets dat commandline regexps voor je kan uitvoeren op een bestand..
Localhost is where the heart is
Inderdaad, zal eens kijken naar Powershell!Remco schreef op donderdag 08 maart 2012 @ 15:08:
Je boedoelt dat je een tekst file wil bewerken met find & replace?
Je zou dat denk ik beter via Vbscript of Powershell kunnnen doen.
"Don't worry, about a thing, Cause every little thing is gonna be alright"
mhoogendam schreef op donderdag 08 maart 2012 @ 15:12:
Hier staan wat voorbeelden van een Bat file en VBS:
http://stackoverflow.com/...nd-edit-lines-in-txt-file
VBScript:
1
2
3
4
5
6
7
8
9
10
11
| Set objFS = CreateObject("Scripting.FileSystemObject") strFile = "C:\dotCMSTest\bin\windows_service\conf\wrapper.conf" Set objFile = objFS.OpenTextFile(strFile) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine objFS.DeleteFile("C:\dotCMSTest\bin\windows_service\conf\wrapper.conf") If InStr(strLine,"{DOTCMS_INSTALLATION_FOLDER}")> 0 Then strLine = Replace(strLine,"{DOTCMS_INSTALLATION_FOLDER}","C:\dotCMSTest") End If WScript.Echo strLine Loop |
Gebruik nu dit, maar als ik de output in een andere file doe dan de bestaande, dan werkt het gewoon. Maar als ik de output in de file wil doen waar de huidige stond dan werkt het niet. Dan krijg ik gewoon een lege file.
Waar zit het foutje?
"Don't worry, about a thing, Cause every little thing is gonna be alright"
Repost sorry!

[ Voor 98% gewijzigd door Gynnad op 08-03-2012 15:47 ]
"Don't worry, about a thing, Cause every little thing is gonna be alright"
Je probeert de file te vroeg te verwijderen.Gynnad schreef op donderdag 08 maart 2012 @ 15:46:
[...]
VBScript:
1 2 3 4 5 6 7 8 9 10 11 Set objFS = CreateObject("Scripting.FileSystemObject") strFile = "C:\dotCMSTest\bin\windows_service\conf\wrapper.conf" Set objFile = objFS.OpenTextFile(strFile) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine objFS.DeleteFile("C:\dotCMSTest\bin\windows_service\conf\wrapper.conf") If InStr(strLine,"{DOTCMS_INSTALLATION_FOLDER}")> 0 Then strLine = Replace(strLine,"{DOTCMS_INSTALLATION_FOLDER}","C:\dotCMSTest") End If WScript.Echo strLine Loop
Gebruik nu dit, maar als ik de output in een andere file doe dan de bestaande, dan werkt het gewoon. Maar als ik de output in de file wil doen waar de huidige stond dan werkt het niet. Dan krijg ik gewoon een lege file.
Waar zit het foutje?
Ik heb de VBS iets aangepast voor je, dubbelklik op de VBS om je file aan te passen:
VBScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| Dim objFS, strFile, objFile, strLine Const ForReading = 1 Const ForWriting = 2 Set objFS = CreateObject("Scripting.FileSystemObject") strFile = "C:\dotCMSTest\bin\windows_service\conf\wrapper.conf" Set objFile = objFS.OpenTextFile(strFile, ForReading) Do Until objFile.AtEndOfStream strLine = objFile.ReadAll If InStr(strLine,"{DOTCMS_INSTALLATION_FOLDER}")> 0 Then strLine = Replace(strLine,"{DOTCMS_INSTALLATION_FOLDER}","C:\dotCMSTest") End If Loop objFile.Close Set objFile = objFS.OpenTextFile(strFile, ForWriting) objFile.WriteLine strLine objFile.Close |
Bedankt!mhoogendam schreef op vrijdag 09 maart 2012 @ 08:39:
[...]
Je probeert de file te vroeg te verwijderen.
Ik heb de VBS iets aangepast voor je, dubbelklik op de VBS om je file aan te passen:
VBScript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Dim objFS, strFile, objFile, strLine Const ForReading = 1 Const ForWriting = 2 Set objFS = CreateObject("Scripting.FileSystemObject") strFile = "C:\dotCMSTest\bin\windows_service\conf\wrapper.conf" Set objFile = objFS.OpenTextFile(strFile, ForReading) Do Until objFile.AtEndOfStream strLine = objFile.ReadAll If InStr(strLine,"{DOTCMS_INSTALLATION_FOLDER}")> 0 Then strLine = Replace(strLine,"{DOTCMS_INSTALLATION_FOLDER}","C:\dotCMSTest") End If Loop objFile.Close Set objFile = objFS.OpenTextFile(strFile, ForWriting) objFile.WriteLine strLine objFile.Close
"Don't worry, about a thing, Cause every little thing is gonna be alright"
Pagina: 1