coldfusionziprenamecoldfusion-10cfzip

How do I rename a file using cfzip?


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


Solution

  • 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.