Moving, renaming, copying, and deleting server files

With cffile, you can create application pages to manage files on your web server. You can use the tag to move files from one directory to another, rename files, copy a file, or delete a file.

The examples in the following table show static values for many of the attributes. However, the value of all or part of any attribute in a cffile tag can be a dynamic parameter.

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 you include the trailing slash (\) when you specify the destination directory. Otherwise, ColdFusion treats the last element in the pathname as a filename. This only applies to copy actions.