Copy link to clipboard
Copied
Apologies for what is no doubt a simple question - I'm trying to help out IT and I'm not a programmer, although maybe one day...
Anyway, I'm going to need to read a text file, and search for a string in that text file and replace it. I see "replace" as a function but I'm not familiar with how to use it. Poking around I found <cffile action=append> and used that to add a line to a text document. (Just a notepad .txt)
Ultimately I'll need to unzip a folder, search and replace the string in a specific file in there, and then re-zip the file, but we'll get to that later. I managed to unzip a folder already, that's easy enough. Putting it all together is my current challenge.
I'm using ColdFusion Builder 2.0
Thanks for any help you guys can give.
file.txt: Contains several lines that all say "All Work And No Play Makes Jack A Dull Boy".
<cffile action="read" file="C:\file.txt" variable="myFile">
<cfset myFile = Replace(myFile,"Dull","Bored","all")>
<cffile action="write" file="C:\file.txt" output="#myFile#" addnewline="no" fixnewline="no">
<cffile action="read" file="C:\file.txt" variable="myNewFile">
<cfoutput>#myNewFile#</cfoutput>
^_^
Copy link to clipboard
Copied
file.txt: Contains several lines that all say "All Work And No Play Makes Jack A Dull Boy".
<cffile action="read" file="C:\file.txt" variable="myFile">
<cfset myFile = Replace(myFile,"Dull","Bored","all")>
<cffile action="write" file="C:\file.txt" output="#myFile#" addnewline="no" fixnewline="no">
<cffile action="read" file="C:\file.txt" variable="myNewFile">
<cfoutput>#myNewFile#</cfoutput>
^_^
Copy link to clipboard
Copied
Very groovy. Thanks!
Copy link to clipboard
Copied
You're welcome. Thanks for marking my response as correct. Have a great weekend.
Copy link to clipboard
Copied
You might want to ignore case-sensitivity. If so, you should use instead
<cfset myFile = replaceNoCase(myFile,"Dull","Bored","all")>
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more