Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Change the root folder of a QuickZip.Zip archive

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #20544 |

    Hi;

     I am creating a zip archive with Xceed.Zip.QuickZip.Zip(@”C:\WorkingDir\Test.Zip”, @”C:\ImportantDir\NecessaryDir\LongNameDir\CustomerDir\”).  This is working great.  All the sub directories and files are archived.

    But when I move “Test.Zip” to “C:\UnzipTest\” and unzip it, it defaults to putting all the files in “C:\UnzipTest\ImportantDir\NecessaryDir\LongNameDir\CustomerDir\”.  Is there a way to make it default to unzipping the files into just “UnzipTest” and not all the other directories?  There are sub directories under “CustomerDir” so I have to preserve the directory structure (and not just dump all the files into the root).  If this isn’t possible to do with QuickZip.Zip, can it be done to the archive after the fact?  Can it be done with some other set of Xceed API’s?

     Thanks!

    Imported from legacy forums. Posted by Atog (had 770 views)

    Diane [Xceed]
    Moderator
    Post count: 1353

    Hi Atog,

    Please refer to the following forum thread:

    http://xceed.com/CS/forums/thread/27610.aspx

    Imported from legacy forums. Posted by Diane [Xceed] (had 263 views)

    User (Old forums)
    Member
    Post count: 23064
    Hi;
    The referenced link suggests using the preservePaths parameter.  Unfortunately, I need to preserve the sub-directories in the folder to be zipped, but I do not want to preserve the directories above that.   If I set preservePaths to false, it dumps all the files in the root of the zip (causing grief with name duplication).  This is why I was asking about changing the root directory of a zip archive.  Does this make more sense?
    Vince

    Imported from legacy forums. Posted by Atog (had 80 views)

    Diane [Xceed]
    Moderator
    Post count: 1353

    Hi Atog,

    You can achieve the effect you are seeking with our FileSystem API.

    With it, you can precisely control the portion of the paths you want stored in the zip archive.

    For example:

       // Select the zip file
       AbstractFile zipFile = new DiskFile( @”C:\WorkingDir\Test.Zip” );

       /* We want to create a new zip file, not update an existing one. As such, any existing
        * zip file must be deleted or else the component will attempt to update the existing
        * zip file. */

       // If the zip file already exists
       if( zipFile.Exists )
          // Delete it
          zipFile.Delete();

       // Create a logical zip archive around the zip file
       ZipArchive zip = new ZipArchive( zipFile );

       // Perform a batch update of the zip archive to maximize efficiency
       using( AutoBatchUpdate batch = new AutoBatchUpdate( zip ) )
       {
          // Select a source folder for files to zip
          AbstractFolder sourceFolder = new DiskFolder( @”C:\ImportantDir\NecessaryDir\LongNameDir\CustomerDir” );

          // Add the files and sub-folders found the source folder to the root of the zip archive
          sourceFolder.CopyFilesTo( zip, true, true );
       }

    Imported from legacy forums. Posted by Diane [Xceed] (had 330 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Diane;

    This code works great.  It is a little slower than the QuickZip call, but it does what I need it to.  

    Thanks a bunch!

    Atog 

    Imported from legacy forums. Posted by Atog (had 747 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.