tags:

views:

43

answers:

3

ive written a quick .bat file that reads in the name of a directory typed in by the user, i store that variable in a variable, and then i want to actually cd to that directory.

i've tested it out with simple directories like "C:," for instance, and that works. however, when i'm dealing with the user entering in something like "C:\Documents and Settings\Desktop," i can't do cd %directory%\sampleFolder.

i keep getting an error of "the system cannot find the path specified," even though i'm using the full name. anyone know how to overcome this?

+1  A: 

How about:

cd "%directory%\sampleFolder"
Philippe Leybaert
yeah, tried that, no go
splatback
Are you sure? This should work (just tested it)
Philippe Leybaert
yeah, thats the weird thing, i thought it should work too, but for some reason it's not...
splatback
It works perfectly!
Ehsan
do you think you could send me the code on how you did it? please :)
splatback
seems like it should work to me.
Dave
@splatback: why don't you show us YOUR code?
Philippe Leybaert
A: 
set /p DIR="path:"
cd %DIR%

Works just fine.

Aviral Dasgupta
strange, still no go for me. but i'll try again later, thanks (and to everyone else) for helping :)
splatback
@splatback: Maybe you're using a version of Microsoft Windows that's too old (older version of cmd.exe? or maybe command.com?) or too new (Microsoft Windows Vista, Microsoft Windows 7), which do not have that directory...
Aviral Dasgupta
You probably shouldn't overwrite the PATH environment variable here ...
Joey
@Johannes : It won't do that. Changing %PATH% from a terminal only changes it for that terminal. The system PATH stays the same... but yes...
Aviral Dasgupta
@Aviral: That's obvious. It still prevents you from running most applications from that console until you either re-set PATH or close it.
Joey
A: 
@ECHO OFF
ECHO Enter Directory
SET/p directory=
CHDIR %directory%

Works for me (Windows 7) but should work for XP/Vista/etc

Mark Baker