Saturday, May 23, 2009

Renaming and Appending in a file using CF

Using ColdFusion's cffile tag, you can rename a file on the server and you can append a file on the server.

Example of Renaming a File


The following code renames the source file with the name specified with the destination attribute.

action="rename"
source="C:\docs\accessLog.txt"
destination="C:\docs\oldAccessLog.txt">

To append a file, you simply use action="append" (instead of action="write").

The contents you specify in this tag are appended to the end of the existing file.If the file doesn't already exist, it is created.

Example of Appending a File

This example declares a variable, assigns the current date and time to it, then appends the result to a file.

dateAccessed = "This page was accessed at this time: " & now()>

action="append"
file="C:\docs\accessLog.txt"
output="#dateAccessed#">

Source : http://www.quackit.com/coldfusion/tutorial/coldfusion_append_file.cfm

No comments:

Computers Add to Technorati Favorites Programming Blogs - BlogCatalog Blog Directory