Whatever message this page gives is out now! Go check it out!

FileCopy

Last update:
May 18, 2026
Note:
You can find the CFFiddle demo of this function and other file functions as part of a project that is shared with you.
Click the button below to launch CFFiddle.
To copy the project in your workspace in CFFiddle, follow the steps below:
  1. Log in with your Gmail or Facebook credentials.
  2. Navigate to the project in the left pane.
  3. Once you make some changes in any cfm in the project, a pop up displays asking you to save the project.
  4. Give the project a suitable name and click Save.
  5. Create a folder named dir1 and upload a text file, myfile.txt.

Description

Copies the specified on-disk or in-memory source file to the specified destination file.

Category

Function syntax

FileCopy(source, destination)

See also

History

ColdFusion 8: Added this function.

Parameters

Parameter
Description
source
Pathname of the on-disk or in-memory file to copy. If not an absolute path (starting with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, which is returned by the getTempDirectory function.
destination
Pathname of an on-disk or in-memory directory or file on the web server where the file is copied. If you specify a filename without a directory path, ColdFusion copies it relative to the source directory.

Usage

Use the following syntax to specify an in-memory file or directory, which is not written to disk. In-memory files speed processing of transient data.
ram:///filepath
The filepath can include directories, for example ram:///petStore/images/poodle.jpg. Create the directories in the path before you specify the file. For more information on using in-memory files, see Working with in-memory files in the Developing ColdFusion Applications.

Example

The following example copies the test1.txt file from the c:\testingdir\ directory to the c:\productiondir\ directory in Windows and names the new copy of the file test2.txt:
<h3>FileCopy Example</h3> 
 <cfset sourcefile="c:\testingdir\test1.txt"> 
 <cfset destinationfile="c:\productiondir\test2.txt"> 
 
 <cfif FileExists(#sourcefile#)> 
 <cfif FileExists(#destinationfile#)> 
 <cfoutput>A copy of #destinationfile# already exists.</cfoutput> 
 <cfelse> 
 <cfscript> 
 FileCopy(#sourcefile#, #destinationfile#); 
 </cfscript> 
 <cfoutput>Copied: #sourcefile# <br> 
 To: #destinationfile#</cfoutput><br> 
 </cfif> 
 <cfelse> 
 <cfoutput>The source file does not exist.</cfoutput><br> 
 </cfif>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page