Reputation: 53
Can anyone please let me know how to write to a notepad file which has multiple contents, and I need to write the output to a particular place.
Say for ex:- I have a notepad with contents
System Name=abc123_1223
System_Ip=xxx.xx.xxx.xxx
Domain_Name= ??
Now I need to update the domain name which I can get from
Set Info = CreateObject("AdSystemInfo")
GetDomainName = Info.DomainDNSName
is there a way?
Upvotes: 0
Views: 1201
Reputation: 200193
You could read the content of the file into a variable:
data = fso.OpenTextFile("C:\path\to\your.txt").ReadAll
replace the line with a regular expression:
Set re = New RegExp
re.Pattern = "^(Domain_Name=).*"
re.IgnoreCase = True
re.MultiLine = True
data = re.Replace(data, "$1" & Info.DomainDNSName)
then write the modified data back to the file:
fso.OpenTextFile("C:\path\to\your.txt", 2).Write data
Upvotes: 1