You want to replace/delete all occurrences of a particular string within all files or files with a certain extension within a directory.
Use the replace function along with cffile and cfdirectory tags.
<cfset testDir = "C:\Documents and
Settings\god\Desktop\test">
<!--- The folder within which search & replace operation
should be performed. --->
<cfdirectory action="list" directory="#testDir#"
name="testDirectory" filter="*.*" recurse="true">
<!--- set filter value to a particular extension to search only
within files with a certain extension. Set recurse
to false if you dont want to include sub directories in
search --->
<cfloop query="testDirectory">
<cfset filepath = "#testDir#\#testDirectory.Name#">
<cffile action="Read" file="#filepath#"
variable="tempFile">
<cfset oldString = "cat">
<cfset newString = "dog">
<cfset tempFile = #ReplaceNoCase(tempFile, oldString,
newString, 'all')#>
<!--- Use replace in place of replacenocase to make the
search case specific. To replace only the first occurence of
the string, set scope to one instead of all --->
<cffile action="write" file="#filepath#"
output="#tempFile#">
</cfloop>
Thazleem Ali :: Software Engineer :: www.toobler.com :: India
+