Click here to Skip to main content
6,822,613 members and growing! (16,695 online)
Email Password   helpLost your password?
Web Development » Applications & Tools » CodeProject Tools     Intermediate License: The Code Project Open License (CPOL)

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

By Nishant Sivakumar

The CPZipStripper tool with source code
C++, C#, Windows, .NET1.1VS.NET2003, Dev
Posted:19 May 2004
Views:54,817
Bookmarked:29 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
28 votes for this article.
Popularity: 6.31 Rating: 4.36 out of 5
1 vote, 3.6%
1

2
2 votes, 7.1%
3
4 votes, 14.3%
4
21 votes, 75.0%
5

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.

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.

    • 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.

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()});
    }            
}
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.

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)

About the Author

Nishant Sivakumar


Member
Nish is a real nice guy living in Atlanta, who has been coding since 1990, when he was 13 years old. Originally from sunny Trivandrum in India, he recently moved to Atlanta from Toronto and is a little sad that he won't be able to play in snow anymore.

Nish has been a Microsoft Visual C++ MVP since October, 2002 - awfully nice of Microsoft, he thinks. He maintains an MVP tips and tricks web site - www.voidnish.com where you can find a consolidated list of his articles, writings and ideas on VC++, MFC, .NET and C++/CLI. Oh, and you might want to check out his blog on C++/CLI, MFC, .NET and a lot of other stuff - blog.voidnish.com

Nish loves reading Science Fiction, P G Wodehouse and Agatha Christie, and also fancies himself to be a decent writer of sorts. He has authored a romantic comedy Summer Love and Some more Cricket as well as a programming book – Extending MFC applications with the .NET Framework.

Nish's latest book C++/CLI in Action published by Manning Publications is now available for purchase. You can read more about the book on his blog.

Despite his wife's attempts to get him into cooking, his best effort so far has been a badly done omelette. Some day, he hopes to be a good cook, and to cook a tasty dinner for his wife.
Location: United States United States

Other popular Applications & Tools articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 25 (Total in Forum: 25) (Refresh)FirstPrevNext
GeneralI've just published an improved version on codeproject Pinmemberdmihailescu6:27 21 Feb '07  
GeneralDirClean PinmemberBassam Abdul-Baki9:14 18 Oct '05  
GeneralIsn't This In The Wrong Section ? PinmemberRick York9:06 25 Jun '05  
GeneralRe: Isn't This In The Wrong Section ? PinstaffNishant Sivakumar9:46 25 Jun '05  
GeneralMultiple Files Pinmemberclick.ok16:09 7 Mar '05  
GeneralGood idea, but... PinmemberScott Robins3:21 21 May '04  
GeneralRe: Good idea, but... PinstaffNishant S4:47 9 Dec '04  
GeneralWhy this vote rating ? PinmemberStephane Rodriguez.2:00 21 May '04  
GeneralRe: Why this vote rating ? PinstaffNishant S2:17 21 May '04  
GeneralRe: Why this vote rating ? PinmemberStephane Rodriguez.2:31 21 May '04  
GeneralRe: Why this vote rating ? PinmemberT1TAN9:29 26 May '04  
GeneralRe: Why this vote rating ? PinmemberMircea Puiu6:47 10 Dec '04  
GeneralZipStudio Article on CodeProject PinmemberWillem Fourie21:15 20 May '04  
GeneralAre article authors really so dumb ... PinsussX. Y.14:29 20 May '04  
GeneralRe: Are article authors really so dumb ... PinstaffNishant S17:41 20 May '04  
GeneralRe: Are article authors really so dumb ... Pinmember.dan.g.20:38 20 May '04  
GeneralRe: Are article authors really so dumb ... PinstaffNishant S21:58 20 May '04  
GeneralRe: Are article authors really so dumb ... PinmemberDavidCrow4:15 15 Aug '05  
GeneralAdding a context menu PinmemberKarby13:11 20 May '04  
GeneralRe: Adding a context menu PinstaffNishant S18:39 20 May '04  
GeneralRe: Especially for folks in Africa... PinstaffNishant S18:41 20 May '04  
Generalalternative Pinmember.dan.g.13:30 20 May '04  
GeneralRe: alternative PinstaffNishant S18:26 20 May '04  
GeneralRe: alternative Pinmember.dan.g.20:36 20 May '04  
GeneralRe: alternative PinstaffNishant S18:40 20 May '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 19 May 2004
Editor: Nishant Sivakumar
Copyright 2004 by Nishant Sivakumar
Everything else Copyright © CodeProject, 1999-2010
Web20 | Advertise on the Code Project