if dir doesnt exist make it

March 31, 2010 at 13:35:37
Specs: Windows XP

I am trying to run something like this:

set drivepath = %CD%
set folder = tester
IF NOT EXIST %drivePath%\%folder% md %drivePath%\%folder%

I can make it work when I place tester into the if statement instead of the folder variable.

what is wrong?

Thanks
Trevor


See More: if dir doesnt exist make it

Report •


#1
March 31, 2010 at 14:08:28

"what is wrong?"

The spaces in the SETs.


=====================================
Helping others achieve escape felicity

M2


Report •

#2
March 31, 2010 at 14:18:20

spaces don't make a difference.

I say again, "I can make it work when I place tester into the if statement instead of the folder variable." this is not changing anything in the code but the variable %folder% is deleted and the tester is in its place.

making that %folder% variable in that path name just doesn't seem to take.

any ideas?

Thanks for the help,
Trevor


Report •

#3
March 31, 2010 at 14:27:13

foremore: any ideas?
Mechanix2Go: The spaces in the SETs.

Report •

Related Solutions

#4
March 31, 2010 at 15:09:33

this still doesn't work

set drivepath=%CD%
set folder=tester
IF NOT EXIST %drivePath%\%folder% md %drivePath%\%folder%

(without the spaces for the sets)

what else?


Report •

#5
March 31, 2010 at 15:29:13

set drivepath=%CD%
set folder=tester
IF NOT EXIST "%drivePath%\%folder%" md "%drivePath%\%folder%"


=====================================
Helping others achieve escape felicity

M2


Report •

#6
March 31, 2010 at 21:05:47

yeah, in this age of insanity, we always need quotes :(
other thing, post your full code? is it inside a block? then you have the delayedexpansion issue going on...
another consideration is why worry? just attempt create the dir and ignore errors? that's what i usually do: md fff 2>nul || goto :testnext
but i do understand if you need finer tuning, like if a file already exists by that name etc.

Report •

#7
April 1, 2010 at 07:58:02

Quotes ... always the same problems return ...

Note that some commands do work nicely though (MS is not consistent here):

D:\Temp>mkdir This is a test

D:\Temp>cd This is a test
The system cannot find the path specified.

D:\Temp>mkdir "This is a test"

D:\Temp>cd This is a test

D:\Temp\This is a test>


Report •

#8
April 1, 2010 at 08:34:33

Thanks all.

It all makes sense now.


Report •


Ask Question