How do I rename a file using cfzip?

403 views Asked by At

I'm having difficulty to rename a file when a document is zipped. Right below, I'm trying to get strings from a document, replace and save as a document with UUID file name. I would like the name of the file to be changed as something that is readable when the file is zipped. How can I do it?

<cfset rtf = FileRead(filepathofdocument) />
<cfset rtf = Replace(rtf,"%newProdYN%",session.input.inputtext) />
<cfset rtf = Replace(rtf,"%ration%",session.input.inputtext2) />
<cfset cfdest = "#GetDirectoryFromPath(session.input.storage.destination)#/#CreateUUID()#.doc" />
<cffile action = "write" 
    file = "#cfdest#"
    output = "#rtf#">
<cfzip action="zip" file="#getTempDirectory()#/#CreateUUID()#.zip">
<cfzipparam source="#cfdest#" entrypath="document.doc" />
<!-- More file sources to zip... -->
</cfzip>

The entry path of cfzipparam tag does not seem to work...

Edited: I have actually follow the tutorial by Ben Nadel blog. http://www.bennadel.com/blog/795-learning-coldfusion-8-cfzip-part-ii-zipping-files-and-directories-with-cfzipparam.htm

2

There are 2 answers

2
Pankaj On BEST ANSWER

You cannot rename the files inside a zip using cfzip.
Providing an entrypath in cfzipparam will only create a subdirectory inside the zip file.
In your case the sub-directory named 'document.doc' will be created inside the zip file.
The name of the file inside the zip will be the same as you provided in cffile while generating the doc file.
Please read this

So you need to first rename the file as desired. And then you can zip it to get the desired results.

0
anna.mi On

Actually, the entrypath attribute allows you to rename the file that will be included in the zip.

Unfortunately there seems to be a bug #3968971 in ColdFusion 11 where this has stopped working.