Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trouble extracting from zip file using SharpZipLib

Status
Not open for further replies.

gib99

Programmer
Mar 23, 2012
51
0
0
CA
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;
        }
 
Perhaps because the ZIP file itself contains the compressed files/folders within a tmp folder.

What do you see if you just open the ZIP file within a ZIP-processing application? Does it show the files within the tmp (and perhaps subsidiary Testdata) folders?
 
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).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top