change directory in batch file using variable

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?

Answers


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.


simple way to do this... here are the example

cd program files
cd poweriso
piso mount D:\<Filename.iso> <Virtual Drive>
Pause

this will mount the ISO image to the specific drive...use


Need Your Help

VirtualBox error on MacOS Sierra

vagrant virtualbox vbox macos-sierra

I am using virtualbox+vagrant for running a virtual machine for development purposes. It was running perfectly fine before I made the stupid mistake of upgrading to Sierra. Here's the trace:

How does Linux determine the next PID?

linux apache linux-kernel kernel

How does Linux determine the next PID it will use for a process? The purpose of this question is to better understand the Linux kernel. Don't be afraid to post kernel source code. If PIDs are