Here's the question:
set Pathname = C:\Program Files
cd %Pathname%
pause
The above doesn't change the directory, as I would expect. Can anybody please tell me why?
Under Windows-10, go to All Apps, Windows System and the open the Command Prompt window. From the command prompt change directory to the batch file directory: cd \Tutorial\batch. Then type the name of the batch file test_conc followed by Enter.
When creating batch files, you can use set to create variables, and then use them in the same way that you would use the numbered variables %0 through %9. You can also use the variables %0 through %9 as input for set. If you call a variable value from a batch file, enclose the value with percent signs (%).
The set
statement doesn't treat spaces the way you expect; your variable is really named Pathname[space]
and is equal to [space]C:\Program Files
.
Remove the spaces from both sides of the =
sign, and put the value in double quotes:
set Pathname="C:\Program Files"
Also, if your command prompt is not open to C:\, then using cd
alone can't change drives.
Use
cd /d %Pathname%
or
pushd %Pathname%
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With