Skip to content

Instantly share code, notes, and snippets.

@dsplaisted
Created October 8, 2012 14:12
Show Gist options
  • Save dsplaisted/3852741 to your computer and use it in GitHub Desktop.
Save dsplaisted/3852741 to your computer and use it in GitHub Desktop.
Zip C# Solution
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ionic.Zip;
using System.IO;
namespace ProjectZipper
{
class Program
{
public const string Root = @"C:\Path\To\Zip";
static HashSet<string> DirectoriesToIgnore = new HashSet<string>();
static HashSet<string> ExtensionsToIgnore = new HashSet<string>();
static void Main(string[] args)
{
DirectoriesToIgnore.Add("obj");
DirectoriesToIgnore.Add("bin");
DirectoriesToIgnore.Add("_upgradereport_files");
ExtensionsToIgnore.Add(".suo");
ExtensionsToIgnore.Add(".db");
ExtensionsToIgnore.Add(".dll");
ExtensionsToIgnore.Add(".user");
ExtensionsToIgnore.Add(".pdb");
ExtensionsToIgnore.Add(".txt");
ExtensionsToIgnore.Add(".sln");
ExtensionsToIgnore.Add(".xml");
ExtensionsToIgnore.Add(".xls");
ExtensionsToIgnore.Add(".xlsx");
ExtensionsToIgnore.Add(".doc");
ExtensionsToIgnore.Add(".docx");
using (ZipFile zip = new ZipFile())
{
AddProjectDirectory(zip, "Proj1");
AddProjectDirectory(zip, "Proj2");
AddProjectDirectory(zip, "Proj3");
zip.AddFile(Path.Combine(Root, "RootSolution.sln"), "");
zip.AddFile(Path.Combine(Root, @"Common\Common.dll"), "Common");
zip.AddFile(Path.Combine(Root, @"Common\Common.pdb"), "Common");
string filename = "<NAME>_" + DateTime.Now.ToString("yyyy_MM_dd") + ".zip";
zip.Save(Path.Combine(Root, filename));
}
}
static void AddProjectDirectory(ZipFile zip, string path)
{
foreach (string dir in Directory.GetDirectories(Path.Combine(Root, path)))
{
if (DirectoriesToIgnore.Contains(Path.GetFileName(dir).ToLowerInvariant()))
{
// skip this directory
continue;
}
string subPath = Path.Combine(path, Path.GetFileName(dir));
//Console.WriteLine(subPath);
AddProjectDirectory(zip, subPath);
}
foreach (string file in Directory.GetFiles(Path.Combine(Root, path)))
{
if (ExtensionsToIgnore.Contains(Path.GetExtension(file).ToLowerInvariant()))
{
// skip this file
continue;
}
zip.AddFile(file, path);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment