Dealing with spaces in command paths can be a hassle. We've all had the experience of sending a script to a colleague at another site and having the script fail because of spaces in paths to input files, output files, commands, or even the script itself. Even if you've tenaciously eliminated path spaces in your script environment, someone who deploys a script at another location might reintroduce spaces in the paths. The optimal solution is to code your scripts so that they aren't affected by the addition of path spaces. If you spend a few minutes to do this at the script-development stage, then test the script by introducing spaces in the debugging stage, you'll be rewarded with a more stable script that can work anywhere and won't require changes to "fix it" to work with spaces.
Problems with spaces in the paths to input or output files are fairly easy to solve. For input files, you can use the For command with the usebackq option to handle input files, as this example shows:
For /F "usebackq tokens=*"
%%i in ("d:\input file.txt") Do Echo %%i
For output files, you can surround the file path with double quotes to handle spaces, like this: . . .
Why become a VIP member?
 |
VIP-only online access |
 |
VIP CD delivered twice a year: offline access to the entire Windows IT Pro article library |
 |
Monthly issue of your choice of Windows IT Pro or SQL Server Magazine |

