MD problem - Two word variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
colmac
Posts: 10
Joined: 29 Nov 2013 11:36

MD problem - Two word variable

#1 Post by colmac » 29 Nov 2013 12:49

Hi folks

Bit of help please for a new member. I'm creating a batch file to create directories from user input, of football team names.

I'm having problems with the last line of this code

Code: Select all

@ECHO OFF
SET /P hteam=Please enter Home Team : 
SET /P ateam=Enter Away Team : 
SET /P tourn=Enter Tournament : 
SET /P venue=Enter Venue : 
SET /P day=Enter 2 digit DAY Date : 
SET /P mth=Enter 2 digit MONTH Date : 

Path = c:\test\
md %mth%"-"%day%" - "%hteam%" v "%ateam%


It does exactly what I want, until I use a two word variable in either the home team or away team variables (hteam or ateam)

If I enter "aaa" for hteam, "ccc" for ateam and todays dates, I get one directory created as follows

11-29 - aaa v ccc

However, if I enter "aaa bbb" for hteam, "ccc ddd" for ateam and todays dates, I get three directories created as follows

11-29 - aaa

bbb v ccc

ddd

Instead of what I want as

11-29 - aaa bbb v ccc ddd

The variable works perfectly, if i use echo %hteam% it reports back "aaa bbb", so the problem is obviously with the MD command.

Is there a simple way to resolve this.

Thanks

Colin

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: MD problem - Two word variable

#2 Post by ShadowThief » 29 Nov 2013 13:17

Putting the team names in quotes when entering them solves the problem for me. For some reason, wrapping the set commands in quotes doesn't work.

colmac
Posts: 10
Joined: 29 Nov 2013 11:36

Re: MD problem - Two word variable

#3 Post by colmac » 29 Nov 2013 16:37

Excellent, that works.

Thanks very much

Colin

Post Reply