Moves a file from one location to another on the server.
ColdFusion 8: Added this function.
FileMove(source,destination)
FileClose, FileCopy, FileOpen, FileRead, FileReadLine, FileWrite, cffile
ColdFusion 8: Added this function.
|
Parameter |
Description |
|---|---|
| source |
Pathname of the file to move. 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 the destination directory or file. If not an absolute path, it is relative to the source directory. |
The following example moves the test1.txt file from the c:\testingdir\ directory to the c:\productiondir\ directory in Windows and renames the file test2.txt:
<h3>FileMove Example</h3>
<cfset sourcefile="c:\testingdir\test1.txt">
<cfset destinationfile="c:\productiondir\test2.txt">
<cfif FileExists(#sourcefile#)>
<cfif FileExists(#destinationfile#)>
<cfoutput>The destination file already exists.</cfoutput>
<cfelse>
<cfscript>
FileMove(#sourcefile#, #destinationfile#);
</cfscript>
<cfoutput>Moved: #sourcefile# <br>
To: <br> #destinationfile#.</cfoutput><br>
</cfif>
<cfelse>
<cfoutput>The source file does not exist.</cfoutput><br>
</cfif>