Results 1 to 3 of 3
  1. #1
    twas brillig's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Location
    Southeastern USA
    Posts
    54
    Reputation
    10
    Thanks
    77
    My Mood
    Amused

    How to Extract folders from ZIP?

    I'm using .NET 4.5 which has ZIP abilities built in.

    Say my project is structured like this:


    Code:
    ├── ListOfFolders.zip (Locked with password)
           └── FolderA
           └── FolderB
           └── FolderC
    └── Hack.exe (Allows you to choose where to install certain folders that are inside the zip)
    The user runs Hack.exe and selects:
    1. Which folders he wants
    2. Where to extract the selected folders


    Would someone be willing to help with this? This would be a useful function to share if I could have some help writing it.

    .NET 4.5 Documentation. Doesn't achieve what I'm trying to do.
     

    Code:
    using System;
    using System****;
    using System****.Compression;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string zipPath = @"c:\example\start.zip";
                string extractPath = @"c:\example\extract";
    
                using (ZipArchive archive = ZipFile.OpenRead(zipPath))
                {
                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
                        {
                            entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
                        }
                    }
                } 
            }
        }
    }


    Those of you that are helping me, be sure to reference
    Code:
    IO.Compression
    Software Developer, Educator, and Gamer.

  2. The Following User Says Thank You to twas brillig For This Useful Post:

    tiger snacks (06-13-2016)

  3. #2
    Eirozytel's Avatar
    Join Date
    Apr 2014
    Gender
    male
    Posts
    41
    Reputation
    10
    Thanks
    1
    My Mood
    Happy
    Please, check youtube before posting any help!

  4. #3
    ChrissHunter's Avatar
    Join Date
    Aug 2012
    Gender
    male
    Posts
    3
    Reputation
    10
    Thanks
    12
    Try this. I'm sure there are better ways of doing it, but it works for me..

    Code:
     public static void extractDir(string directoryName, string zipPath, string extractPath)
            {
    
                //Open Zip Archive
                using (ZipArchive archive = ZipFile.OpenRead(zipPath))
                {
                    //For each file in archive
                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        //If Directory name equals directoryName          Splitting the Directory path, to get the first directory name of the path
                        //Console.WriteLine(Path.GetDirectoryName(entry.FullName));
                        if (Path.GetDirectoryName(entry.FullName).Split('/')[0].Equals(directoryName) || Path.GetDirectoryName(entry.FullName).Split('\\')[0].Equals(directoryName))
                        {
                            //Combine the destination path
                            string combinedPath = Path.Combine(extractPath, Path.GetDirectoryName(entry.FullName));
                            //Create directory(s)
                            if (!Directory.Exists(combinedPath))
                            {
                                Directory.CreateDirectory(combinedPath);
                            }
    
                            //Check if the entry is a directory
                            if (!Directory.Exists(Path.Combine(combinedPath, entry.Name)))
                            {
                                entry.ExtractToFile(Path.Combine(combinedPath, entry.Name));
                            }
                        }
    
                    }
                }
            }
    A function call would look like this:

    extractDir("FolderInZipFileToExtract","Zipfile.zip ","DestinationPath");

    The Structure inside the folder to extract is kept the same.

Similar Threads

  1. How to extract links from a website that closed yesterday?
    By creepycanada in forum General Hacking
    Replies: 2
    Last Post: 11-06-2014, 09:49 PM
  2. how to extract a website from a program?
    By w4ssup in forum General
    Replies: 11
    Last Post: 06-16-2014, 08:51 PM
  3. [Help] how to save dll from resources to temp folder.? [solved]
    By blackgaming in forum Visual Basic Programming
    Replies: 2
    Last Post: 08-14-2011, 12:27 AM
  4. TUTORIAL - How to prevent Warrock from crashing!
    By Darky in forum WarRock - International Hacks
    Replies: 25
    Last Post: 07-06-2007, 09:31 PM
  5. (Request) A tutorial on how to extract addresses from trainers
    By englishpom in forum WarRock - International Hacks
    Replies: 9
    Last Post: 05-19-2007, 10:14 PM

Tags for this Thread