Click here to Skip to main content
15,881,710 members
Articles / Programming Languages / C#
Article

A tool to strip zips of unwanted files before submitting to CodeProject

Rate me:
Please Sign up or sign in to vote.
4.77/5 (30 votes)
19 May 2004CPOL3 min read 106.9K   1.2K   35   26
The CPZipStripper tool with source code

Image 1

Fig. 1 - The red colored files will get stripped

Introduction

The CPZipStripper is a simple tool I've been using when editing and submitting articles on CP, and all it does is to remove unwanted files from the zips - like debug and obj folder files, suo files, pdb files, aps files etc. to name a few. It's a one-click tool - so you don't have to waste time opening the zip in WinZip or some such tool and then manually deleting unwanted files.

It would be very nice if article authors would use this tool on their zips before sending it to us, so that the size of the mails received by the editors will be considerably lesser.

Installation

Unzip the three files in release.zip to any permanent folder of your choice :-

  • CPZipStripper.exe - This is the main executable (.NET IL exe targetted at FW 1.1)
  • CPZipStripperCfg.xml - Configuration file
  • ICSharpCode.SharpZipLib.dll - the DLL that I use for accessing the zip files (SharpZipLib)

Now just run CPZipStripper.exe once and exit. That's all.

Using the tool

You can either drag/drop a zip into the program window or right click a zip file and choose the "Open with ZipStrip" option, but for the context menu item to get added, you'll need to run the program at least once - as it does not have a separate installer.

Image 2

Fig. 2 - Context menu item for zip files in Explorer

The buttons

  • Modify Config - This will open the config XML file in your windows XML editor - if you don't have one, it will report an error. If so, manually open the XML file in Notepad and make your changes.

    Image 3

    • The extensions node lists all extensions that need to be deleted
    • The paths node lists all paths that you want to be deleted (thus if you have debug in there, any file whose extract path contains debug is deleted)
    • The files node lists any specific filenames that you want deleted
  • Refresh Listbox - If the zip file has changed or you have made modifications to the XML config file, please hit the "Refresh Listbox" button
  • Strip Unwanted files - This will remove all the unwanted files (shown in red in the listbox) and will replace the zip with a clean file, but also backs up the old file.
  • Exit Program - Use this one with case, as it closes the program ;-)

Interesting points

Here are some odd things I learned :-)

Handling drag/drop was really easier than I expected it to be. First you need to set the Form's AllowDrop property to true. Then just handle the DragEnter and DragDrop events.

C#
private void MainForm_DragDrop(object sender, 
    System.Windows.Forms.DragEventArgs e)
{
    Array arr = (Array)e.Data.GetData(DataFormats.FileDrop);
    if(arr != null)
    {
        //Doing it asynchronously else Explorer will freeze too                
        BeginInvoke(new DroppedFileHandler(FilterZip),
            new object[] {arr.GetValue(0).ToString()});
    }            
}
C#
private void MainForm_DragEnter(object sender, 
    System.Windows.Forms.DragEventArgs e)
{
    //To change the mouse cursor if there are any files
    e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? 
        DragDropEffects.Copy : DragDropEffects.None;
}

If you are interested in a generic function that will let you add a context menu item for a specific file type :-

See my blog entry : A simple C# function to add context menu items in Explorer and here's the function.

C#
private bool AddContextMenuItem(string Extension, 
 string MenuName, string MenuDescription, 
 string MenuCommand)
{
  bool ret = false;
  RegistryKey rkey = Registry.ClassesRoot.OpenSubKey(
    Extension);
  if(rkey != null)
  {
    string extstring = rkey.GetValue("").ToString();
    rkey.Close();                         
    if( extstring != null )
    {
      if( extstring.Length > 0 )
      {
        rkey = Registry.ClassesRoot.OpenSubKey(extstring,true);
        if(rkey != null)
        {
          string strkey = "shell\\" + MenuName + "\\command";
          RegistryKey subky = rkey.CreateSubKey(strkey);
          if(subky != null)
          {
            subky.SetValue("",MenuCommand);
            subky.Close();
            subky = rkey.OpenSubKey("shell\\" + MenuName, true);
            if(subky != null)
            {
              subky.SetValue("",MenuDescription);
              subky.Close();
            }                 
            ret = true;
          }
          rkey.Close();
        }
      }
    }
  }
  return ret;
}

Conclusion

The UI is not much to look at, but the tool's worked for me. Let me know if anyone has any suggestions/feedback through the article forum.

Post-Conclusion (dan g's tool)

While my tool is meant for stripping unwanted files from zip files, dan g has an excellent article here on CP, describing a 3-in-1 tool that can be used to package VC++ and .NET project files. I strongly urge people to take a look at that one :-

After all, prevention is better than cure, eh?

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
Nish Nishant is a technology enthusiast from Columbus, Ohio. He has over 20 years of software industry experience in various roles including Chief Technology Officer, Senior Solution Architect, Lead Software Architect, Principal Software Engineer, and Engineering/Architecture Team Leader. Nish is a 14-time recipient of the Microsoft Visual C++ MVP Award.

Nish authored C++/CLI in Action for Manning Publications in 2005, and co-authored Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on CodeProject.com and another 250+ blog articles on his WordPress blog. Nish is experienced in technology leadership, solution architecture, software architecture, cloud development (AWS and Azure), REST services, software engineering best practices, CI/CD, mentoring, and directing all stages of software development.

Nish's Technology Blog : voidnish.wordpress.com

Comments and Discussions

 
Questionnice Pin
BillW3315-Feb-13 3:56
professionalBillW3315-Feb-13 3:56 
GeneralI've just published an improved version on codeproject Pin
dmihailescu21-Feb-07 5:27
dmihailescu21-Feb-07 5:27 
GeneralDirClean Pin
Bassam Abdul-Baki18-Oct-05 8:14
professionalBassam Abdul-Baki18-Oct-05 8:14 
QuestionIsn't This In The Wrong Section ? Pin
Rick York25-Jun-05 8:06
mveRick York25-Jun-05 8:06 
AnswerRe: Isn't This In The Wrong Section ? Pin
Nish Nishant25-Jun-05 8:46
sitebuilderNish Nishant25-Jun-05 8:46 
GeneralMultiple Files Pin
Clickok7-Mar-05 15:09
Clickok7-Mar-05 15:09 
GeneralGood idea, but... Pin
Scott Robins21-May-04 2:21
Scott Robins21-May-04 2:21 
GeneralRe: Good idea, but... Pin
Nish Nishant9-Dec-04 3:47
sitebuilderNish Nishant9-Dec-04 3:47 
QuestionWhy this vote rating ? Pin
Stephane Rodriguez.21-May-04 1:00
Stephane Rodriguez.21-May-04 1:00 
AnswerRe: Why this vote rating ? Pin
Nish Nishant21-May-04 1:17
sitebuilderNish Nishant21-May-04 1:17 
GeneralRe: Why this vote rating ? Pin
Stephane Rodriguez.21-May-04 1:31
Stephane Rodriguez.21-May-04 1:31 
AnswerRe: Why this vote rating ? Pin
T1TAN26-May-04 8:29
T1TAN26-May-04 8:29 
AnswerRe: Why this vote rating ? Pin
Mircea Puiu10-Dec-04 5:47
Mircea Puiu10-Dec-04 5:47 
GeneralZipStudio Article on CodeProject Pin
Willem Fourie20-May-04 20:15
Willem Fourie20-May-04 20:15 
GeneralAre article authors really so dumb ... Pin
X. Y.20-May-04 13:29
sussX. Y.20-May-04 13:29 
GeneralRe: Are article authors really so dumb ... Pin
Nish Nishant20-May-04 16:41
sitebuilderNish Nishant20-May-04 16:41 
GeneralRe: Are article authors really so dumb ... Pin
.dan.g.20-May-04 19:38
professional.dan.g.20-May-04 19:38 
GeneralRe: Are article authors really so dumb ... Pin
Nish Nishant20-May-04 20:58
sitebuilderNish Nishant20-May-04 20:58 
GeneralRe: Are article authors really so dumb ... Pin
David Crow15-Aug-05 3:15
David Crow15-Aug-05 3:15 
GeneralAdding a context menu Pin
Karby20-May-04 12:11
Karby20-May-04 12:11 
GeneralRe: Adding a context menu Pin
Nish Nishant20-May-04 17:39
sitebuilderNish Nishant20-May-04 17:39 
GeneralRe: Especially for folks in Africa... Pin
Nish Nishant20-May-04 17:41
sitebuilderNish Nishant20-May-04 17:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.