There are several posts, out there in the wild, about using ColdFusion's built-in VFS support for working with zip files. I posted the other day (and fairly quickly removed it), about using the FileMove() function to rename a zip file and all of it's contents. What I discovered, though, was that this wasn't possible. Even though the documentation states that FileMove() and FileCopy() support the in-memory file system, I found that zip files are not included in that support. Luckily there was the CFScript Community Components project, for working with zip files within script. And, though zip files were unsupported, "ram://" was still a viable option:
/** * Rename a zip file, and the internal files as well * @access private * @returntype boolean * @output false */ function RenameZipAndContents (required string srcPath, string destPath=ARGUMENTS.srcPath, required string srcFileRoot, required string newFileRoot) { // Create the zip object var zip = CreateObject("component", "com.ccc.zip").Init(); // Create a temp directory in RAM var vfsDir = "ram:///"& ARGUMENTS.newFileRoot &"/"; DirectoryCreate(LOCAL.vfsDir &"zip"); // Unzip the source file to the RAM directory zip.unzip(destination=LOCAL.vfsDir &"zip", file=ARGUMENTS.srcPath & ARGUMENTS.srcFileRoot &".zip"); // Get a list of the files var files = DirectoryList(LOCAL.vfsDir &"zip", false, "query"); // Loop the file list for (LOCAL.file in LOCAL.files) { // Get the file extension var ext = Right(LOCAL.file.name, 4); // Rename the file FileMove(LOCAL.vfsDir &"zip/"& LOCAL.file.name, LOCAL.vfsDir &"zip/"& ARGUMENTS.newFileRoot & LOCAL.ext); // Zip up renamed file in new zip zip.zip(file=ARGUMENTS.srcPath & ARGUMENTS.srcFileRoot &".zip", source=LOCAL.vfsDir &"zip/"& ARGUMENTS.newFileRoot & LOCAL.ext); // Delete original file from zip zip.delete(file=ARGUMENTS.srcPath & ARGUMENTS.srcFileRoot &".zip", entrypath=LOCAL.file.name); } // Delete the temp RAM directory DirectoryDelete(LOCAL.vfsDir, true); // Rename the original zip file FileMove(ARGUMENTS.srcPath & ARGUMENTS.srcFileRoot &".zip", ARGUMENTS.destPath & ARGUMENTS.newFileRoot &".zip"); return true; }Yes, that's a lot of jumping through hoops, and the multiple zip operations really drag out something that should be pretty simple. I'm not sure why zip isn't supported by these operations. Maybe some future revision will correct that.