sounds more like you want to edit the file, append is easy, if you want to edit then i think you will need to read file into memory (FSO.OpenTextFile) edit the contents in memory, then write it back (FSO.CreateTextFile)
dont let the TextFile thing put you off, you just tell it to create a file call xxx.bat
Set FSO = CreateObject("Scripting.FileSystemObject")
Set dicSource = CreateObject("Scripting.Dictionary")
'dont know what a dic just lazy and i hate redim
'1 is for reading
Set tsSource = FSO.OpenTextFile("c:\test.bat", 1, True)
Do While Not tsSource.AtEndOfStream
sLine = ""
sLine = Trim(tsSource.ReadLine)
If sLine = "echo hello world" Then
sLine = "echo hello celia1"
End If
dicSource.Add dicSource.Count, sLine
Loop
tsSource.Close
Set tsSource = Nothing
Set tsSource = FSO.CreateTextFile("c:\test.bat", True)
'True isto overwrite existing file
For Each aLine In dicSource
tsSource.WriteLine dicSource.Item(aLine)
Next
tsSource.Close
Set tsSource = Nothing
Set FSO = Nothing
I write this script :
Sub FtpdConfig(ftpdFile, psaIP)
Dim fso, ftpdFileOri, fori, fbat
Set fso = CreateObject("Scripting.FileSystemObject")
ftpdFileOri = ftpdFile&".ori"
If (fso.FileExists(ftpdFileOri))=False Then
fso.CopyFile ftpdFile, ftpdFileOri
End If
Set fori = fspenTextFile(ftpdFileOri, ForReading, False)
Set fbat = fspenTextFile(ftpdFile, ForWriting, False)
Do While fori.AtEndOfStream <> True
ReadLineTextFile = fori.ReadLine
If Instr(ReadLineTextFile, "FtpServer.server.config.host") = 0 Then
fbat.WriteLine ReadLineTextFile
Else
fbat.WriteLine "FtpServer.server.config.host="&psaIP
End If
Loop
yeap, my iterations were required (ie. double loops) cause i was editing a file as opposed to creating a new one based on the contents of an existing one, but there you go
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.