Re: Replace string in .inf file
From: Bernard Dejonckheere (no.bdejonckheere.spam_at_no.hotmail.com.spam)
Date: 03/07/04
- Next message: Steve Fulton: "Re: reference to Outlook Express"
- Previous message: Chris Barber: "Re: Where is the session object?"
- In reply to: Maxence: "Replace string in .inf file"
- Next in thread: Joe Earnest: "Re: Replace string in .inf file"
- Reply: Joe Earnest: "Re: Replace string in .inf file"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 7 Mar 2004 12:48:46 +0100
I had the same problem once,
the thing I do now is in cmd-prompt:
type original.inf > work.inf
and do my operations on that one
Bernard
-----------------------------------------------------------
"Maxence" <arkoven(supprimez-ceci)@hotmail.com> wrote in message
news:#6NZ7RwAEHA.3804@TK2MSFTNGP09.phx.gbl...
Hi,
I would to replace one string by another string an .inf file which was
create by Windows.
I have a script which works with all my test files (txt, inf) but it's don't
work with the original .inf file. All strings are replace by??????
characters.
Probably a problem with unicode text because all .inf files begin with :
"
[Unicode]
Unicode=yes
[Version]
signature="$CHICAGO$"
Revision=1
"
By exemple, I use the secsetup.inf in c:\Windows\repair folder (XP Pro
station)
I don't know how I can bypass the unicode text in my script and especially
that this file, after replace string, can always be used by Windows. II
have tried to use unicode option to create my temp File... but no success
Someone has an idea ?
Thanks @ lot !!!
Maxence
This is my script... Maybe someone will be interested... you can use with
all files but be careful don't use with really unicode file otherwise you
break it ;-)
'=================================================
Dim Shell
Dim System
Set Shell = CreateObject("Wscript.Shell")
Set System = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const ForWriting = 2
'Path of the .inf File
PathFile = "C:\Temp\MyFile.inf"
'Old Text
OldTxt = "oldvalue"
'New Text
NewText = "newvalue"
ChangeText PathFile, oldTxt, NewText
'-----------------------------------------
'Sub ChangeText
'-----------------------------------------
Sub ChangeText(FileINF, MyText, NewText)
Dim ThisFile
Set ThisFile = System.OpenTextFile(FileINF,ForReading)
countx=0
While Not ThisFile.AtEndOfStream
strFile = strFile & ThisFile.ReadLine & vbcrlf
Wend
ThisFile.Close
Do until instr(strFile, MyText) = False
countx= countx + 1
strFile = Replace(strFile, MyText, NewText,1,1)
Loop
TempFile strFile, FileINF
MsgBox MyText & " was found and replaced with " & newtext & " " & countx &
" times.", , "Toms cool text replace script"
End Sub
'------------------------------
'Sub TempFile
'function that writes results to the temp file and move it insteed old file
'------------------------------
Sub TempFile( newString,FileINF )
myfile = FileINF
Set fso = CreateObject("Scripting.FileSystemObject")
OutFile = "C:\#temp#.txt"
set textstream = fso.OpenTextFile(myFile,1,true)
Set OutStream=fso.CreateTextFile(OutFile,True)
OutStream.WriteLine( newstring)
textstream.close
OutStream.Close
fso.CopyFile OutFile, myfile, true
fso.DeleteFile OutFile
End Sub
- Next message: Steve Fulton: "Re: reference to Outlook Express"
- Previous message: Chris Barber: "Re: Where is the session object?"
- In reply to: Maxence: "Replace string in .inf file"
- Next in thread: Joe Earnest: "Re: Replace string in .inf file"
- Reply: Joe Earnest: "Re: Replace string in .inf file"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|