Friday, May 1, 2009

How to make Windows %path% readable

If like me your Windows %path% looks something like this:

Python26Libidlelib;C:cygwinbin;C:Program FilesWindows 
Resource KitsTools;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWS
Downloaded ProgramFiles;C:Program FilesIBMDirectorbin;C:
Program FilesDiskeeper CorporationDiskeeper;c:Program 
FilesMicrosoft SQL Server90Toolsbinn;C:Program Files
Rationalcommon;c:scripts;C:Program FilesjEdit;C:Program 
FilesQuickTimeQTSystem;C:Program FilesTortoiseSVNbin;C:
ipdsdevaxis2axis2c-rel-1.3.0lib;C:Program FilesJava

Then save this to "road.bat" somewhere on your path:

@echo off
rem source:
for %%i in ("%path:;=" "%") do @echo %%i

When you run C:\>road all those paths are nicely split and one-lined:

and you can do cool things like C:\>road | find /i "Perl" to find out where Perl is hiding.

To paraphrase the (brilliant) author VinsWorldcom, this one-liner

wraps the %PATH% ENV var in double quotes and then replaces all the semicolon separators with a double-quote, space, double quote. This effectively puts double quotes around all the paths (so spaces won't give any troubles) then use the for loop to list each newly double-quoted string.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.