Windows Short File Paths
Installing PHPDev 5 Beta on my laptop today I ran into some trouble with the paths to the installation. The error code hinted that the problem was with the php.ini having long windows paths rather than short.
For some background on that, windows uses two types of paths when referring to the files on your computer. The long version is the one typically seen when browsing your computer.
C:\Program Files\Some Program\somefilehere.exe
The short version, however, is archaic and hard to determine. It basically comes down to a capitalized part of the directory, one of those wavy dashes (~), and a number for directories. It might look like this.
C:\PROGRA~1\SOME~1\somefilehere.exe
This removes spaces and other characters that might interfere with some programs and cause them to crash. In order to get phpdev5 working, I’d probably simply have to replace the long file name in php.ini – the php configuration file – with the short one because it appears the spaces are causing errors.
This is an easy fix, but finding short path names on your computer is not. There used to be a trick I knew within windows to find this, but I’ll be honest and say if there is I can’t remember it.
I went looking for this old trick and found this instead, courtesy of DevX.
@echo off
if not exist %1 echo %1 – no such file or directory exists&goto :EOF
echo.
echo Full PathName : %1
echo.
echo Short PathName : %~s1
echo.
echo.
This is a batch file. I used to talk about batch files a lot when I wrote my column at The Nettle Magazine called Format C:\.
These days batch files are rather archaic as well. Most people do not use them, and I must admit it’s been several years since I have as well, but they can still be very useful. Just like the one above.
Here is the trick. Simply create a new text document in the C:\ folder on your computer, copy the above code and paste it in. Save this file as pathname.bat. The article on DevX says to run this using Visual Basic, but it can also be run through the command prompt in Windows.
Go to Start->Run, type cmd, and press enter to bring up the command prompt. Now, if you want to know the path to a file all you have to do is type the following.
C:\pathname.bat C:\Program Files\Some Program\program.exe
Naturally, you would replace the path to the file with your own pathname and file you’d like to find, and you will then be treated with both the long and short filepaths and names.
I hope this is as helpful to you as it was to me.


