Adobe COLDFUSION 9 Manual page 1254

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using External Resources
Action
Example code
Move a file
<cffile action="move" source="c:\files\upload\KeyMemo.doc" destination="c:\files\memo\">
Rename a file
<cffile action="rename" source="c:\files\memo\KeyMemo.doc"
destination="c:\files\memo\OldMemo.doc">
Copy a file
<cffile action="copy" source="c:\files\upload\KeyMemo.doc"
destination="c:\files\backup\">
Delete a file
<cffile action="delete" file="c:\files\upload\oldfile.txt">
This example sets the ReadOnly flag bit for the uploaded file:
<cffile action="Copy"
source="c:\files\upload\keymemo.doc"
destination="c:\files\backup\"
attributes="ReadOnly">
Note: Ensure that you include the trailing slash (\) when you specify the destination directory. Otherwise, ColdFusion
treats the last element in the path as a filename. This rule only applies to copy actions.
Reading, writing, and appending to a text file
In addition to managing files on the server, you can use the cffile tag to read, create, and modify text files. As a result,
you can do the following things:
• Create log files. (You can also use
• Generate static HTML documents.
• Use text files to store information that can be incorporated into web pages.
Reading a text file
You can use the
tag to read an existing text file. The file is read into a local variable that you can use anywhere
cffile
in the application page. For example, you could read a text file and then insert its contents into a database, or you could
read a text file and then use one of the string replacement functions to modify the contents.
Read a text file
1
Create a ColdFusion page with the following content:
<html>
<head>
<title>Read a Text File</title>
</head>
<body>
Ready to read the file:<br>
<cffile action="read"
file="C:\inetpub\wwwroot\mine\message.txt"
variable="Message">
<cfoutput>
#Message#
</cfoutput>
</body>
</html>
Replace C:\inetpub\wwwroot\mine\message.txt with the location and name of a text file on the server.
2
to create and write to log files.)
cflog
Last updated 8/5/2010
1249

Advertisement

Table of Contents
loading

Table of Contents