Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Un-zip multiple files at once or an entire directory

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

    i’m evaluating Xceed .net zip component, i’m unable to find how to compress or un-compress an entire directory of files without writing additional code to do each file individually. Is the Xceed component able to do this?

    Imported from legacy forums. Posted by iislogs (had 1970 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi!

    It sure can. If you want to compress all files and subfolders in that source folder, you do this:

    <code> ZipArchive zip = new ZipArchive( new DiskFile( @”d:\foo.zip” ) );
    DiskFolder source = new DiskFolder( @”d:\data” );

    source.CopyTo( zip, true );</code>

    The zip file will remember the relative path of each item, including the “data” part. If you do not want to include subfolders, you can do this:

    <code> ZipArchive zip = new ZipArchive( new DiskFile( @”d:\foo.zip” ) );
    DiskFolder source = new DiskFolder( @”d:\data” );

    source.CopyFilesTo( zip, false, true );</code>

    If you want to zip all files recursively, without remembering their relative path, you simply change “false” above with “true”. If two files have the same name, the second one will overwrite the first.

    The only time you will need to loop is if you want to compress everything recursively, keeping each item’s path without the “data” part. In that case, you would do:

    <code> ZipArchive zip = new ZipArchive( new DiskFile( @”d:\foo.zip” ) );
    DiskFolder source = new DiskFolder( @”d:\data” );

    zip.BeginUpdate();

    try
    {
    foreach( FileSystemItem item in source.GetItems( false ) )
    item.CopyTo( zip, true );
    }
    finally
    {
    zip.EndUpdate();
    }</code>

    Hope this helps.

    Imported from legacy forums. Posted by Martin (had 3142 views)

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