Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Adding specific files to Zip, maintaining relative paths

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

    I have a List<string> of files that is built dynamically based on a FileSystemWatcher. The data is relative to the path I’m watching, e.g.:

    apps.reg
    LocalSystem\apps.reg

    (total count is 500-1500 entries)

    I’ve been trying to create a zip file to store a snapshot of these files, however it seems that my folders are not maintained, and because I’m setting overwrite = true, the last file with the same name gets inserted. What am I doing wrong:
    (source = DirectoryInfo, fileList = List<string>)

    ZipArchive zip = new ZipArchive(zipFile);
    zip.BeginUpdate();
    for (int i = 0; i < fileList.Count; i++)
    {
    if (!String.IsNullOrEmpty(fileList[i]))
    {
    DiskFile file = new DiskFile(Path.Combine(source.FullName, fileList[i]));
    file.CopyTo(zip, true);

    }
    }
    zip.EndUpdate();

    I tried using a ZippedFolder, however the performance was too poor as there was no Begin/End Update methods.

    Imported from legacy forums. Posted by James (had 3789 views)

    User (Old forums)
    Member
    Post count: 23064

    I did try the following, and got what I wanted, however the performance was really slow… howe can I improved the performance:

    for (int i = 0; i < fileList.Count; i++)
    {
    if (!String.IsNullOrEmpty(fileList[i]))
    {
    sourceFolder.CopyFilesTo(zip, true, true, fileList[i]);
    }
    }

    Imported from legacy forums. Posted by James (had 418 views)

    User (Old forums)
    Member
    Post count: 23064

    You can still use the Begin/End Update methods while using ZippedFolder. When you’re in a Begin/End Update block, any operation on the ZipArchive is postponed until the EndUpdate call, even if it is done through the ZippedFolder/ZippedFile objects you have created. Remember that these classes take a ZipArchive as an argument of their respective constructor.

    Imported from legacy forums. Posted by André (had 284 views)

    User (Old forums)
    Member
    Post count: 23064

    In the 2nd posting, I was able to acheive what I wanted with ZipArchive.CopyFilesTo(), however the performance is very poor. For 17 Folders, 390 files, the start/stop was:

    Start: 2/16/2007 12:56:48 PM End: 2/16/2007 1:10:49 PM ~= 14:01

    This is occuring in a BeginUpdate(), EndUpdate()

    Is there something I can do differently to speed this up? I’m assuming that since I have recursive = true, and have a list for each file, it is searching for each file recursively, which is the source of the performance issue…

    How can I maintain the folder structure, specifying exactly which files I want from various folders?

    Imported from legacy forums. Posted by James (had 274 views)

    User (Old forums)
    Member
    Post count: 23064

    Well, in your first scenario you get the file you want to zip directly. What you can do is initialize a corresponding ZippedFile within the archive, and simply copy the file directly to this new ZippedFile. This way, it will not be recursive, and you will have the path into the archive.

    e.g.:

    ZipArchive archive = new ZipArchive( zipFile );
    archive.BeginUpdate();
    for (int i = 0; i < fileList.Count; i++)
    {
    if (!String.IsNullOrEmpty(fileList[i]))
    {
    ZippedFile zippedFile = new ZippedFile( zip, Path.Combine( SomePath, fileList[i] ) );
    DiskFile fileToZip = new DiskFile(Path.Combine(source.FullName, fileList[i]));
    fileToZip.CopyTo( zippedFile, true );
    }
    }
    archive.EndUpdate();

    Note that you will not be able to use the source.FullName to create the ZippedFile, since it must be a path without a drive letter in it, due to the file structure within an archive.

    e.g.:

    “D:\temp\fileToZip.txt” -> not good.
    “\temp\fileToZip.txt” -> good.

    Imported from legacy forums. Posted by André (had 4598 views)

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