Where to find the writing of Harley and Diane Pebley

Sunday, February 24, 2008

A new simple utility

I use a really handy piece of software called TiddlyWiki. It can be used for many things. My use is as a free-form textual database. I have a couple that I keep all sorts of things in. A smattering of things include phone numbers, photo ideas, to do lists and blog articles in various forms of completeness from ideas to complete articles. It can be easily searched. Links can be made between items trivially. Items can be tagged. Once you learn the secret codes, formatting text doesn't interrupt the flow of writing. It's really cool and I highly recommend it.

However, this recommendation is not the point of this article. I ran into a problem today while making a tiddler (the basic unit of text). To understand the problem, you need to know that TiddlyWiki allows you to put links to other things by simply putting their URL in the text. It recognizes that it's a URL and automatically makes it clickable.

(A URL is the text that shows in a web browser's address bar. For web pages, they typically start with "http:\\". What is not quite so well known is there are other things they can start with. Alternate options supported by most browsers include "ftp:\\" to get information from FTP sites and "file:\\" to read from the local computer's filesystem. Browsers may have plug-in modules to support other types of information.)

Today, while doing some writing, I wanted to refer to Word files stored on my hard drive. No problem, I just used Windows Explorer to find the file and copied the directory from the address bar, pasted it into the tiddler and then copied the filename into the tiddler. Finally I put "file:\\" in front and presto! A link to my file. Click it and Word opened up with the document. Yeah, it worked!

So now the problem: The link was long. Really long. Insanely long. I mean it was so long the filename spilled off the edge of the browsers window. Long filenames are nice when all you are looking at is a single directory. Have several sub-directories with long names and the combined path, while readable, is pretty unwieldy. On my system, the path for "My documents" is "C:\Documents and Settings\harley_pebley\My Documents". Sixty-two characters just to get to the default location for storing files. Yikes! You can see if you add a couple more levels for personal organization within here and add a long name on the document (in this case a really long one created by someone else), file names with paths can get absurdly long.

Well, Windows there's a simple solution. (Sorry Mac and *nix users, I don't know of a solution on these platforms.) Windows still has its roots in the old DOS file system. For those of you old enough to remember, before the days of long names, filenames consisted of 8 characters with a 3 character extension. This notation is still supported by Windows. Believe it or not, there are still old applications that don't know how to handle long filenames; this allows them to still work.

So, all I needed to do is change the long file name path to one of these short paths. Hmm. How? I knew you could get the short name of a file using "dir /x" from the command prompt but this didn't give me the whole path. I'd have to build it directory by directory by hand. Yuck! "There's got to be a better way" I told myself. As a software developer, I knew there was a single, simple function call in the operating system to do this conversion. This had to be exposed somewhere for easy access by users.

A bit of googling around revealed others asking the same question but all the answers were to just use "dir /x" and type in the results. There were a few who helpfully provided perl scripts to automatically parse a string, running "dir" on each directory and parsing out the short name from the results. While well meaning, this meant I had to install a perl interpreter on my machine and figure out how to make it all work. Helpful but not too practical. Some searching on Microsoft's web pages only gave sample code in Visual Basic on how to access the method I already knew about. I could not find a simple way to get this.

What do you do when you need a tool that doesn't exist? You make it of course. This long story is to introduce my new really small utility: ShowShortName. It's a console application, meaning you have to use it from the command window prompt, that shows the short name of files. The link goes to a zip file containing the Pascal source code for the utility, a compiled version and a text readme file with installation and usage instructions.

Using this, I can now open a command window, type in the showshortname command followed by a quote character, paste the file's long pathname into the window, type in a closing quote character and press return. And there I have it, the short name in all its compressed, unreadable but more usable glory. Then it's just a matter of copying that from the command window back into the tiddler giving me a link that doesn't cause my browser to go goofy. In the future, I can just navigate to the appropriate directory and use the utility with just the filename. If it's given a file without a path, the current directory is added to the front. Much simpler.

I hope someone else finds this useful.