0

How can I duplicate a file on my server? I can read it with <cffile action="read"> but I want to duplicate it under a new name.

I found <cffile action="copy"> but I can only duplicate it to another directory. I need to duplicate it in the same directory.

Thnx.

1
  • cffile action="copy" works fine for same directory. If you're getting an error post the details and your exact code. Aug 23, 2012 at 16:03

3 Answers 3

4

No, <cffile action="copy"> can create a copy in the same directory as the existing file. As long as you use a different file name. So if you are unable to do so, something else is at fault. Please post your code and any error messages.

1
  • 3
    The docs do say under the description of cffile "copy".... "Copies a file from one directory to another on the server. ". However following on from Leigh comment it does say under the "destination" attribute description that if you omit the path and just give it a filename then ColdFusion will use a path relative to the source. Aug 23, 2012 at 13:21
1

Untested but one option could be to read the file as binary instead and then write this to a new file.

Example taken from the bottom of the Adobe docs here:- http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_f_08.html

<cffile action = "readBinary" file = "C:\inetpub\wwwroot\cfdocs\getting_started\photos\somewhere.jpg" variable = "aBinaryObj">

    <!--- Output binary object to JPEG format for viewing. --->
    <cffile action="write" file = "c:\files\updates\somewhereB.jpg" output = "#toBinary(aBinaryObj)#">

    <!--- HTML to view image. --->
    <img src="C:\files\updates\somewhereB.jpg">
1
  • Thank you for the fast response! Aug 23, 2012 at 13:12
1

The accepted answer is over complicating it. This is all you need:

<cffile action="COPY" source="C:\inetpub\wwwroot\cfdocs\getting_started\photos\somewhere.jpg" destination="C:\inetpub\wwwroot\cfdocs\getting_started\photos\somewhere_Copy.jpg">
1
  • True, as already mentioned twice, cffile copy is not limited to the same directory. So something else is going on...
    – Leigh
    Aug 23, 2012 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.