我正在尝试使用以下代码创建一个zip文件...我有一个像“D:\ smad”这样的文件夹。我有2个文件。我想创建一个名为“smad.zip”的zip文件夹。但我找到了一些“将文件添加到Zip存档”的代码..这里就是这样做
var file = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("AChrom", Components.interfaces.nsIFile);
file.initWithPath(file.path+"\\smad.zip");
var file11 = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("AChrom", Components.interfaces.nsIFile);
file11.initWithPath(file.path+"\\home.txt");
var zipWriter = Components.Constructor("@mozilla.org/zipwriter;1", "nsIZipWriter");
var zipW = new zipWriter();
zipW.open(file, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
zipW.addEntryFile(file11.path, Components.interfaces.nsIZipWriter.COMPRESSION_DEFAULT, file11, false);
zipW.close();
使用上面的代码zip文件没有创建...请帮我...这个代码有什么问题...还有其他方法在javascript的帮助下创建一个zip文件夹。谢谢你提前
答案 0 :(得分:0)
我得到了上述问题的解决方案......
var file = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("AChrom", Components.interfaces.nsIFile);
file.initWithPath(file.path+"\\smad.zip");
var filenew = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("AChrom", Components.interfaces.nsIFile);
filenew.initWithPath(filenew.path+"\\home.txt");
const PR_RDONLY = 0x01;
const PR_WRONLY = 0x02;
const PR_RDWR = 0x04;
const PR_CREATE_FILE = 0x08;
const PR_APPEND = 0x10;
const PR_TRUNCATE = 0x20;
const PR_SYNC = 0x40;
const PR_EXCL = 0x80;
var zipWriter = Components.Constructor("@mozilla.org/zipwriter;1", "nsIZipWriter");
var zipW = new zipWriter();
zipW.open(file, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
zipW.addEntryFile("home.txt", Components.interfaces.nsIZipWriter.COMPRESSION_DEFAULT, filenew, false);
zipW.close();