I have a configuration file that i would like to update with classic asp.
Lets say the conf file looks like this:
[Parameters]
param1 = 'foo'
param2 = 'boo'
param3 = 'moo'
param4开发者_如何学Go = 'choo'
What I would like to do is write a script to change param2
and param4
to have different.
As I am not all that great with asp, I was wondering what would be the best way to do this? ie is there a way I can increment the line and look for param2
and param4
and then somehow replace the entire line?
Any help will be much appreciated.
I don't think there's a way you can random access write a file but you can use the file object to read in a file line by line, check if it's the line you want and if so update it, and write another one out.
Dim fs : Set fs = Server.CreateObject("Scripting.FileSystemObject")
Dim file : Set file = fs.OpenTextFile(Server.MapPath("file.config"))
Dim line
Do While Not fs.AtEndOfStream
line = file.ReadLine()
If IsThisTheLineIWant(line) Then
' some magic
Else
' some hand waving
End If
Loop
精彩评论