Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Add files to a folder in .zip file.

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

    I want to create a C:\test.zip from the following files and folders:

    C:\1.txt
    C:\a\2.txt
    D:\b\e\3.txt
    D:\b\e\4.txt

    I want the source files added to the .zip file as follows:

    C:\1.txt –> Root\1.txt
    C:\a\2.txt –> Root\2.txt
    D:\b\e\3.txt –> Root\e\f\3.txt
    D:\b\e\4.txt –> Root\e\f\5.txt

    so that when I upzip my C:\test.zip to C:\myDirectory\, I will get the following:

    C:\myDirectory\1.txt
    C:\myDirectory\2.txt
    C:\myDirectory\e\f\3.txt
    C:\myDirectory\e\f\5.txt

    Is there a way to do this with XCeed? I’m looking for a method that allows me add my source file to a specific folder which is in a .zip file. Something like:

    Add (“C:\b\e\3.txt”, “C:\test.zip”, “e\f\3.txt”);
    Add (“C:\b\e\4.txt”, “C:\test.zip”, “e\f\5.txt”);

    Thanks.

    Imported from legacy forums. Posted by thuyen (had 3751 views)

    User (Old forums)
    Member
    Post count: 23064

    You can copy any DiskFile, wathever its path, into any ZippedFile, whatever its path. But you’ll obviously will have to copy each file one by one, or at least each folder you need folder groups.

    I would do something like this:

    <code> AbstractFile zipFile = new DiskFile( @”c:\test.zip” );

    // Create new zip file. Remove if updating existing zip file.
    if( zipFile.Exists )
    zipFile.Delete();

    AbstractFolder zipRoot = new ZipArchive( zipFile );

    AbstractFile[][] filePairs = new AbstractFile[][]
    {
    new AbstractFile[] { new DiskFile( @”c:\1.txt” ), zipRoot.GetFile( @”1.txt” ) },
    new AbstractFile[] { new DiskFile( @”c:\a\2.txt” ), zipRoot.GetFile( @”2.txt” ) },
    new AbstractFile[] { new DiskFile( @”d:\b\e\3.txt” ), zipRoot.GetFile( @”e\f\3.txt” ) },
    new AbstractFile[] { new DiskFile( @”d:\b\e\4.txt” ), zipRoot.GetFile( @”e\f\5.txt” ) }
    };

    using( new AutoBatchUpdate( zipRoot ) )
    {
    foreach( AbstractFile[] filePair in filePairs )
    {
    filePair[ 0 ].CopyTo( filePair[ 1 ], true );
    }
    }
    </code>

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

    User (Old forums)
    Member
    Post count: 23064

    When you added a file into an .zip file as you did, did it actually make a file smaller (compress) or just straight copying files?

    If it does not compress files, is there a way to code this program problem so that it will make the .zip filesize smaller than size of all files combine?

    Thanks,
    -Thuyen.

    Imported from legacy forums. Posted by thuyen (had 276 views)

    User (Old forums)
    Member
    Post count: 23064

    That’s the whole idea behind the Xceed FileSystem. The “Zip” implementation of a file and a folder compresses and decompresses files automatically. But for your code, you’re just copying files from one location (disk) to another (in a zip file), or vice versa. The fact that a zip file compresses its data and writes local and central headers is hidden from you, just like the fact that files on disk are written in partitionned clusters with FAT entries.

    If you want to have control over the default compression method and level check the “DefaultXyz” properties (like DefaultCompressionMethod) on the ZipArchive instance.

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

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