Visual Basic .Net
Visual Basic .Net

Reputation: 225

Spaces in Names in Command Line

I have a small problem.

In my folder if I have the following files

Script1.sql
Script2.sql

The below code works. However, if I have spaces in the file name like

Script 1.sql
Script 2.sql

It fails. Can someone assist me in modifying the below to ensure the script captures file names with spaces?

@echo off

set /p sname= Please enter the servername:
set /p dbname= Please enter the databasename:

ECHO started the batch process at %TIME%  >output.txt

for %%f in (*.sql) do (
sqlcmd.exe  -S %sname% -d %dbname% -i %%f  >>output.txt


)
pause

Upvotes: 0

Views: 52

Answers (2)

Arko Elsenaar
Arko Elsenaar

Reputation: 1729

You can use the ^ character to escape spaces. So this should be the solution:

Script^ 1.sql

Upvotes: 0

Luca B.
Luca B.

Reputation: 648

Use double/single quotes around those names. That should be enough to "escape" (not litterally escaping but you get the point) those white spaces

Upvotes: 3

Related Questions