Can't zip nested folders

Hi people ! does anyone here used the java.util.zip package I need to zip a series of nested folders  similar to this

MyProjects/MicrosoftProjects/MyProgram/bin/Debug/MyProgram.dll

however the ZipOutput stream requires a file,in this case MyProgram.dll.Does anyone have a workaroud regading the above issue I keeping hitting the FileNotFoundException as i specifed the sourcestream at MyProjects/


regards
Wilson



Answer this question

Can't zip nested folders

  • Mestreechteneer

    FYI.

    string SomewhereYouWantToZip = "Pictures";

    ZipOutputStream s = new ZipOutputStream(SomewhereYouWantToZip);
    s.SetLevel(6); // 0 - store only to 9 - means best compression
    ZipFolder(SomewhereYouWantToZip, SomewhereYouWantToZip, s);



  • GilesT

    Hi jacky, thanks for the example,however, are you using the ICSharpCode dll or the java.util.zip

    Another question, when i intially call the method Do I pass in the root folders into the method >



  • JJMack

     bmann225 wrote:
    Hi people ! does anyone here used the java.util.zip package I need to zip a series of nested folders  similar to this

    MyProjects/MicrosoftProjects/MyProgram/bin/Debug/MyProgram.dll

    however the ZipOutput stream requires a file,in this case MyProgram.dll.Does anyone have a workaroud regading the above issue I keeping hitting the FileNotFoundException as i specifed the sourcestream at MyProjects/


    regards
    Wilson


    Does anyone noe how to zip a directory using the ICSharpCode.SharpZipLib dll

  • ejunkie2005

    I'm using ICSharpCode.SharpZipLib.dll

    when i intially call the method
    just call the function when you want to zip folder, the function will loop to get all folders and files inside the root folder where you pass in.
    P.S. you need to declare the ZipOutputStream before call the method.

    Do I pass in the root folders into the method
    yes, just call

    ZipOutputStream s = new ZipOutputStream(SomewhereYouWantToZip);
    s.SetLevel(6); // 0 - store only to 9 - means best compression
    ZipFolder(SomewhereYouWantToZip, SomewhereYouWantToZip, s);

    hope it can help you.



  • Harini K P

    Actually, if you are using ICSharpCode.SharpZipLib you can download the sample in their website, there has a sample project called CreateZipFile, you can reference that project. and just modify the zip file part to the code what I post before.

    http://www.icsharpcode.com/OpenSource/SharpZipLib/Download.aspx



  • Jonathan Caves - MSFT

     Jacky Yiu wrote:

    FYI.

    string SomewhereYouWantToZip = "Pictures";

    ZipOutputStream s = new ZipOutputStream(SomewhereYouWantToZip);
    s.SetLevel(6); // 0 - store only to 9 - means best compression
    ZipFolder(SomewhereYouWantToZip, SomewhereYouWantToZip, s);



    Sorry Jacky,

    however the ZipOutPutStream() requires a System.IO.Stream path to be passed in and not a string.

  • murali_k1

    What happens if at the end of the basecase i need to zip additional files

    given the structure

    Pictures/Family/25102005_Outing.jpg
    Pictures/Family/26102005_BBQ.jpg

    What i want to achieve is 1 zip file created and the final Family folder has the 2 photos.

  • MkJnr

    sorry, the thing should be.

    string SomewhereYouWantToZip = "Pictures";
    string TheZipFilePath = "Somewhere";

    ZipOutputStream s = new ZipOutputStream(File.Create(TheZipFilePath));
    s.SetLevel(6); // 0 - store only to 9 - means best compression
    ZipFolder(SomewhereYouWantToZip, SomewhereYouWantToZip, s);

    Sorry for the mistake...
     :$



  • Instigator

    Define a new ZipEntry using the root folder

    and recursive loop the folder and file under the folder and add it to the ZipOutputStream

    public void ZipFolder(string RootFolder, string CurrentFolder, ZipOutputStream zStream)
    {
     string[] SubFolders = System.IO.Directory.GetDirectories(CurrentFolder);
     foreach (string Folder in SubFolder)
     {
      ZipFolder(RootFolder, Folder, zStream);
     }

     ZipEntry entry;
     entry = new ZipEntry(CurrentFolder.Substring(RootFolder.Length) + "/");
     entry.DateTime = DateTime.Now;

     zStream.PutNextEntry(entry);

     //Start loop files under CurrentFolder
     //End
    }



  • Can't zip nested folders