Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Name conflict with CFFILE COPY

Status
Not open for further replies.

jarla

Programmer
Jan 2, 2001
34
0
0
FI
HI!
Once again little problem :(
I have a gallery-page and customers can send their photos to the gallery also via normal email. Coldfusion use CFX_IMAP4 -tag to check specified mailbox every five minutes and it works good. BUT: Every customer have, of course, their own folder for pictures. No problem, I´ve programmed script which loops over every message, take all (picture)attachments and move them from attachments -folder to customer´s imagefolder. But very often customer use, for example, digital camera which use the same system to save images. So then customer can send images with a same name.
So: I need to check if there already is a image with a same name in the destination folder before I do the CFFILE ACTION="COPY" -script. If there is, then new file would be renamed to imagename(1) etc. before the copy.
I hope you understood my problem, this has been a hard day... ;)
 
Why don't you just use the "nameconflict" attribute of the cffile tag? That's what it's made to do, Skip, Overwrite, or MakeUnique if it finds a name conflict.

Hope This Helps!

Ecobb

"Alright Brain, you don't like me, and I don't like you. But lets just do this, and I can get back to killing you with beer." - Homer Simpson
 
Thanks Ecobb, but in this situation it´s not usable because all attachments go first to same "attachment" -folder. After that the script use the CFFILE ACTION="COPY" to copy attachments from attachmentfolder to customer´s own imagefolder. "COPY" -action don´t have option to use the "nameconflict" -parameter. Or do it?
 
Yes, you are correct. "COPY" does not have the "nameconflict" attribute. Oops, sorry about that!

OK, maybe you could try something like this:

This will give you a list of all files in the destination folder

<cfdirectory action=&quot;LIST&quot; directory=&quot;C:\whatever\&quot; name=&quot;ImageList&quot;>


Now, I'm assuming you already have the name of the image you're tying to load set as a variable somewhere. Just loop through the above list and have CF react accordingly:

<cfloop index=&quot;i&quot; list=&quot;ImageList&quot;>
<cfif i = ImageVarName>
...code to change image name...
</cfif>
</cfloop>


Then, once you've renamed your image (if you need to) you can copy it over. I know this is a little vague, but I would need to see your code to be able to get it exact.


Hope This Helps!

Ecobb

&quot;Alright Brain, you don't like me, and I don't like you. But lets just do this, and I can get back to killing you with beer.&quot; - Homer Simpson
 
Why not do :

<CFIF fileExists(&quot;C:\filename.ext&quot;)>

Duplicate File rename it to somehting different

<CFELSE>

Ok, continue with copy commands

</CFIF>
 
Thanks for all instructions! I decided to name all images that come by email, again with dynamically generated filename like this:
<cfset newname=&quot;#timeformat('#Now()#', &quot;HHmmss&quot;)##randnumber#_#attachmentsent#&quot;>
Then the code use that #newname# to copy the file to customer´s imagefolder. When I tried to use those &quot;nameconflict&quot; -methods I was stuck in this situation:
1. Customer send file called &quot;image.jpg&quot; by email
2. Next day same customer send different image with the same &quot;image.jpg&quot; -name. No problem, program find that it´s already used and it renames it with a name &quot;image(1).jpg&quot;
3. Next time same customer use again the same &quot;image.jpg&quot; -name when he/she is sending file by email. Well, program find that &quot;image.jpg&quot; is already in use and it renames it like &quot;image(1).jpg&quot;..... then it overwrites another picture.

So it should check the folder also after first renaming. After all, that dynamic filename works great :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top