2013-06-04 73 views
0

我想創建一個zip文件,使用下面的代碼...我有一個文件夾,如「D:\ smad」。我有2個文件。我想創建一個名爲「smad.zip」的zip文件夾。但我發現了一些代碼「將文件添加到Zip檔案」 ..我在這裏做這樣使用thunderbird api創建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文件也沒有創造......請幫我out..whats錯這個代碼...而且也沒有任何其他方式提前

回答

0

我得到了上述問題的解決方案,以創建javascript..Thanks的幫助下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 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();