How can I go to a subdirectory without specifying its whole path?
So when I am in
C:/users/USERNAME/desktop/project/build/
How can I then navigate to
C:/users/USERNAME/desktop/project/build/directory 1/
I tried
cd /directory 1
But this results in
The system cannot find the path specified.
I want to use something as simple as the ..
command, which goes one directory back without specifying its whole path. Is there something similar to change to a subdirectory?
On Windows the directory separator is \
... the backslash character. The slash character /
is used on Windows for parameters/options of a command/executable/script.
For compatibility reasons like #include
instructions in C/C++/C# with a relative path using /
as directory separator Windows accepts also paths with /
and automatically convert them to \
when a string is interpreted as file/folder name with a path. That is done by the file IO functions used by Windows executables on accessing the file system of a storage device.
A path starting with a backslash is a path relative to root of current drive.
For that reasons cd /Directory 1
is executed as cd /D irectory 1
which means with interpreting /D
at beginning of the directory argument string as optional option /D
by command CD to change also the drive and the rest of the directory argument string not enclosed in double quotes as name of the subdirectory to change current directory to. The subdirectory irectory 1
does not exist on your machine.
If the directory name starts with any other character than letter D
and using /
instead of \
at beginning of the directory argument string like on using cd /Folder 1
, there would be executed cd "C:\Folder 1"
with drive C:
being the current drive.
There are three types of relative paths:
.\
or with directory name...\
.\
..\
and ..\
can be also used anywhere inside a path after a directory separator multiple times and Windows automatically resolves the path to an absolute path.
So correct would be using cd "Directory 1"
, or not recommended cd Directory 1
.
The help of command CD output on running cd /?
explains that the command CD does not require enclosing a path with one or more spaces in double quotes as usually required because a space is usually interpreted as separator between arguments to pass to a command, executable, or script.
It is nevertheless best practice to always enclose the path in double quotes because of some other characters require path being enclosed in double quotes to interpret (nearly) all characters in path as literal characters.
For example a directory has the name Test & Doc
. With cd Test & Doc
the Windows command processor executes cd Test
and next tries to find an executable or script with Doc
and Doc.*
having a file extension listed in environment variable PATHEXT
in current directory or any directory listed in environment variable PATH
because of the ampersand is interpreted as unconditional AND operator for execution of multiple commands on a single command line. But on using cd "Test & Doc"
the entire double quoted string is interpreted as name of a directory to change to by the Windows command processor.
BTW: All internal (included in cmd.exe
... the Windows command processor) and external commands (executables installed by default in %SystemRoot%\System32
) can be started with the parameter /?
in a command prompt window to get displayed the help for this command.
cd /?
cmd /?
pushd /?
popd /?
More details on Windows commands can be found at
The Microsoft documentation about Naming Files, Paths, and Namespaces offers even more details about file names and how paths are interpreted by Windows kernel. Everybody writing program or script code for applications or scripts executed on Windows should have read this documentation page at least once from top to bottom.
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