Tuesday, December 09, 2008

VFP: File and folders via indirection

Last night one of my clients was implementing their vertical market application half way around the world. The onsite support people were reporting an error when the app was started: "Invalid path or file name."

Thanks to the new error handler we implemented in the app I tracked this problem down to a single line of code:

CD &lcDataPath

Looking at the value of lcDataPath it became instantly apparent what the problem was, spaces in the folder name. The tech support person right away explained to me the standard for the install is no spaces in the folder names. This site deviated from the standard folder name recommended by my customer. Now she knows exactly why the original developers proclaimed this "requirement" years ago.

I have not been burned by spaces in code for a long time because I always use indirection in my code whenever I deal with file names or folders.

CD (lcDataPath)
DELETE FILE (lcFileName)

I posted this issue on Twitter earlier today and Andrew MacNeill noted this is probably a great rule to add to Code Analyst up on VFPX. I agree. I am now curious how many developers do not test their applications in folder structures with spaces in the name. I just checked my development machine and all my test folders are space free. But I do install my applications on a virtual machine in the Program Files folders and this tests out the space problem.

Yet one more reason why we have standards at White Light Computing and why the adoption of industry best practices gives us more solid deployments and apps in production. Fortunately the onsite tech people were okay with renaming the folder, otherwise my customer would have been hiring us to review the application for other macro expansion gotchas.

Labels: , ,


At 1/22/2009 04:03:00 PM, Anonymous Christof Wollenhaupt said...

I find a lot of them, even among developer tools. Usually I spot them right away since at least on my XP machines my projects are all stored in C:\Documents and Settings\name\My Documents\Projects. There's three spaces in there. With this structure I also run into the maximum path length of 260 when copying some of the sample provided by Microsoft into the projects folder provided by... Microsoft. No wonder on Vista it's now C:\users\name\documents... ;)

At 3/10/2009 09:22:00 AM, Blogger Randy Jean said...

I was a convert from macro expansion years ago. Initially it was due to speed but also because of needing to escape periods in file names, etc. Using the parenthesis also executes faster. I'm amazed at how many programmers still default to using macro expansion. Old habits I guess.

At 4/08/2009 12:03:00 AM, Blogger Jim said...

Curiously, I've always intentionally used folders with embedded spaces -- both because I find them more readable and also because that means that the problem will always have to be solved on my machine first anyway.


Post a Comment

<< Home