Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFFILE action="read"

Status
Not open for further replies.

omerdurdu

Programmer
Joined
Jul 21, 2001
Messages
72
Location
TR
Is someone can help me?
Thanks in advance!
I have 1000 text files in a directory and I would like to replace a word in each of these text files. Can someone give me an idea how can I automate that. I did use CFFILE like this but I cant go more:

<cffile action=&quot;read&quot; file=&quot;c:\xml\step.txt&quot; variable=&quot;file_content&quot;>
<cfoutput>
#Replace(Hello, Hello1)# (This is not working)
</cfoutput>

Any help! I appreciate it!
 
Hi,

<cffile action=&quot;read&quot; file=&quot;c:\xml\step.txt&quot; variable=&quot;file_content&quot;>

Contents of your file will be stored in the file_content variable.

Try :
Replace(file_content, &quot;hello&quot;, &quot;hello1&quot;, &quot;ALL&quot;)

will replace all occurances of hello to hello1.
 
Thank you for your respond. I tried but it didnt work again
here is the code:

<cffile action=&quot;read&quot; file=&quot;c:\xml\step.txt&quot; variable=&quot;file_content&quot;>
<cfoutput>#Replace(file_content, &quot;map&quot;, &quot;mapo&quot;, &quot;ALL&quot;)#</cfoutput>


Do you have any idea? Thanks
 
Hi,
Check the contents of file_content variable by displaying it on the browser :


<cfoutput>#file_content#</cfoutput>

Check whether actual / correct conents of the file is being stored in that varible or not??
 
Thank you
you are so quick
Ok I found the problem, it is case sensitive, that is why I got it wrong.

But I have another question if you dont mind?

I have a F directory. I have like 1000 text files in this directory,
Do you have any idea how I am gonna automate this replacing procedure.
Do I have to write a cfloop?
 
No Problem!

I'm not sure though, but i guess you have to use cfoop.

Good luck!
 
Do you need to automate this, or this a one time thing? - tleish
 
You can use cfdirectory to get you the list of .txt files , loop through it like you would a query and use your replace code thing there.

e.g

<cfdirectory name=&quot;qryGetList&quot; directory=&quot;c:\xml\&quot; filter=&quot;*.txt&quot;>

<cfloop query=&quot;qryGetList&quot; index = &quot;idx&quot;>
<cffile action=&quot;read&quot; file=&quot;c:\xml\#idx#&quot; variable=&quot;file_content&quot;>

etc.....
</cfloop>

Keep in mind that it may be a little slow and intensive with that many files. (I've done this before, but it should work)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top