Sunday, February 26, 2006

New utility: PathFind.exe

When I recently encountered the issue where an old version of ildasm.exe instead of the latest version was unexpectedly used when run from the command line, due to the folder of the older version being located in my machine's PATH first, I thought of the which utility for unix/linux, which returns the location of a file on the path. (The "path" in this context is the set of folders that the operating system will search for a program that the user has requested to run from the command prompt or Windows' Start | Run dialog.) The "which" utility would have allowed me to immediately verify that the copy of ildasm.exe that was being run was not located in the expected directory.

I wasn't aware of a similar command-line utility for Windows, and writing one seemed like a simple enough matter, so I decided to write one. The utility would just need to get the value of the PATH environment variable, parse the individual directories out of the path, then do a "file exists" check in each PATH folder, checking for the specified file name.

I was able to put the program together fairly quickly, and it seemed like something that people might find to be generally useful, so I spent a little bit more time to polish it, then added it to the utilities page on my homepage for download as PathFind.exe. The extra polish included automatic searching for the file with extensions from the PATHEXT environment variable (.com, .exe, .bat, and so on) for files for which no extension is specified (so the user can search for just "iisreset" instead of having to search for "iisreset.exe"), as well as things like input validation, error handling, and a help message.

As it turns out, Microsoft also has released a similar utility, where.exe, available for download with some of its resource kits and SDKs such as the Windows 2003 SP1 Platform SDK (but not apparently available as a stand-alone download). The where.exe utility supports wildcard searches and some other advanced options, but doesn't support automatic PATHEXT extension searching.

No comments:

Post a Comment

Non-spammers: Thanks for visiting! Please go ahead and leave a comment; I read them all!

Attention SPAMMERS: I review all comments before they get posted, and I REPORT 100% of spam comments to Google as spam! Why not avoid getting your account banned as quickly -- and save us both a little time -- by skipping this comment form and moving on to the next one on your list? Thanks, and I hope you have a great day!