Wednesday, January 25, 2006

cleanPath.py: an IronPython utility

During my CodeCamp presentation, I introduced a very sketchy (and logically flawed) script to examine a PATH environment variable and clean out unwanted elements.

Since then, I created a much-improved version in IronPython which, I think, is actually worth using. Features:
  • Conveniently view and delete path items
  • Nonexistent directories and duplicate items are flagged, and can be purged with one keystroke
  • works on PATH, CLASSPATH, PYTHONPATH, PERL5LIB, etc.
It's Windows-only, but only Windows makes editing your PATH such a pain, anyway.

The code is here.

Right now, you need IronPython, and use "ironpythonconsole cleanPath.py" to run it. I need to figure out how to generate an .exe, since getting set up with IronPython is too much to ask just to clean up your PATH.

[EDIT: An executable is ready now. See my next blog entry.]

5 comments:

Anonymous said...

Catherine,

Thanks for the utility.

When I saved it / copied it, I lost all the formatting. Although Python made it pretty easy to put it back in, you may want to see if you can present it in such a way to preserve your formatting.

Thanks, again.

Pavan Podila said...

You may also want to check out Microsoft Shell (MSH/Monad). It can probably simplify the script.

Unknown said...

Thansk, anonymous! I'm sorry, I'd never tested out my Blogger page from IE. From Firefox, you can cut/paste the code into a text editor and keep the formatting, but you're right... from IE, cut/paste loses the carriage returns. Ouch!

Anonymous said...

---

Anonymous said...

Nice one, Catherine. I'm about to start something in IronPython myself to look for duplicate files on my PC.

I like Python, but haven't seen much evidence that there's a good way to do Windows forms yet. IronPython could be a good interim measure until Firefox/XUL gets Python.

Incidentally, I'm going to try and decouple as much of the .net stuff as I can to retain reusability.