Skip to main content
Participant
July 23, 2009
Question

cffile copy, move ... filename conflict?

  • July 23, 2009
  • 4 replies
  • 7107 views

Hi:

I am working on a file copy and move operation, I realized in cffile action="upload", coldfusion can detect if filename already exist and give some error or overwrite, and also give result attribute for me to know what's going on.

But in cffile action="copy" and action="move", there is no nameConflict attribute and result attribute. So I don't know what's going on while copy or move operation, and the worst thing ever, it didn't even generate an error or something or at least give me result for me to detect what's going on. Does it overwrite? How do I check result?

Thanks.

    This topic has been closed for replies.

    4 replies

    BKBK
    Community Expert
    Community Expert
    July 24, 2009
    Cpthk0, you're right to worry. I think the default behaviour of <cffile action="copy"> and <cffile action="move"> is to overwrite any file of the same name in the destination directory.

    And, I think, that ain't OK.

    Participant
    July 24, 2009

    http://xiaoganmijiu.com/ado/tp.gif

    Dileep_NR
    Inspiring
    July 24, 2009

    Hi,,

    try this lgic

    check the file exits in that folder

                   <!--- If already exists  file its renmaed --->
                     <cfif FileExists(fullPath)>
                         <cfset newfilePart = dateformat(now(),'dd_mmm_yyyy')& timeformat(now(),'hh_mm_ss_L')>      
                            <cfset FileName = listinsertat(FileName,(listlen(FileName,".")),newfilePart,".") >
                    </cfif>          

    BKBK
    Community Expert
    Community Expert
    July 23, 2009

    Cpthk0, you're right to worry. I think the default behaviour of <cffile action="copy"> and <cffile action="move"> is to overwrite any file of the same name in the destination directory.

    ilssac
    Inspiring
    July 23, 2009

    As far as I can tell, the engineers figured if you are doing <cffile action="move"....> or <cffile action="copy"...> you are working within your own file system and would create your own file management logic.  To that end they created functionality like fileExists() and <cfdirectory...> that can be used to read the state of a directory before and|or after move or copy operations.

    Whereas with <cffile action="upload"....> you are working with files from outside users who may (and probably should) have little idea about your file system.