... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2007-08-30

Windows BAT vs. Spaces in Filenames

The BAT construct FOR %%I in (%~dp0\somefile.txt) will fail if the current directory has a space in the fully qualified path.  It will interpret the path as a list of space-separated paths instead.  The usual solution, to put the path in quotes, will not work in this context since FOR treats a quoted string as a literal line to be processed instead of as a single filename.

The workaround is to use %~dps0 instead of %~dp0.  Thus, short 8.3 filenames will be used instead, eliminating the problem.

Blog Archive