CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2011
    Posts
    63

    [RESOLVED] trouble extracting files using SharpZipLib

    Hello,

    I'm using SharpZipLib and I'm trying to understand why my files are not extracting to the target directory that I specify.

    I have a zip file under C:\tmp\TestData\. I want to extract it to C:\tmp\TestData\temp\. Instead, it extracts it to C:\tmp\TestData\temp\tmp\TestData\. That is, it seems to be taking the original path which the zip file is under and tacking that onto the target directory that I specify. Why is it doing this?

    Here's my code:

    Code:
            private bool UnzipAcmZipFile(string pathAndName)
            {
                if (!File.Exists(pathAndName) ||
                    !pathAndName.EndsWith(acmZipExtensionStr))
                {
                    return false;
                }
    
                FastZip fastZip = new FastZip();
                fastZip.ExtractZip(pathAndName, "C:\\tmp\\TestData\\temp\\", string.Empty);
    
                return true;
            }

  2. #2
    Join Date
    May 2012
    Location
    Bonn, Germany
    Posts
    43

    Re: trouble extracting files using SharpZipLib

    Maybe the files are stored with a path inside the Zip file.

  3. #3
    Join Date
    Nov 2011
    Posts
    63

    Re: trouble extracting files using SharpZipLib

    Quote Originally Posted by TomasRiker View Post
    Maybe the files are stored with a path inside the Zip file.
    How can I prevent this?

    Here's how I create the zip file:

    Code:
                    ZipFile zipfile = ZipFile.Create(pathAndNameExtStripped + acmZipExtensionStr);
                    zipfile.BeginUpdate();
                    zipfile.Add(pathAndFileName);
                    zipfile.CommitUpdate();
                    zipfile.Close();

  4. #4
    Join Date
    Nov 2011
    Posts
    63

    Re: trouble extracting files using SharpZipLib

    Here's how I was zipping the files:

    Code:
    ZipFile zipfile = ZipFile.Create(pathAndNameExtStripped + acmZipExtensionStr);
    zipfile.BeginUpdate();
    zipfile.Add(pathAndFileName);
    zipfile.CommitUpdate();
    zipfile.Close();
    Here's how I'm zipping the files now:

    Code:
    ZipFile zipfile = ZipFile.Create(pathAndNameExtStripped + acmZipExtensionStr);
    zipfile.BeginUpdate();
    zipfile.Add(pathAndFileName, fileNameWithoutPath);
    zipfile.CommitUpdate();
    zipfile.Close();
    This seems to work. By adding fileNameWithoutPath as the second argument to zipfile.Add(...) (the entryName), I'm actually able to name the entry (the file) which seems to determine how it gets unzipped (I'm assuming the default name included the full path).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured