2013-06-04 7 views
0

다음 코드를 사용하여 zip 파일을 만들려고합니다. "D : \ smad"와 같은 폴더가 있습니다. 나는 그것에 2 파일이 있습니다. "smad.zip"이라는 이름의 zip 폴더를 만들고 싶습니다. 하지만 난 내가 잘못 out..whats 도와주세요 ... 작성되지 않은 위의 코드 zip 파일을 사용하여이썬더 버드 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(); 

같이하고있는 중이 야 .. 여기에 "우편 아카이브에 파일 추가"에 대한 몇 가지 코드를 발견 이 코드 ... 그리고 또한 내가 위의 질문에 대한 해결책을 가지고

답변

0

사전에 javascript..Thanks의 도움으로 지퍼 폴더를 만들 수있는 다른 방법이 ....

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();