Paths
suggest changeFile and directory paths follow certain conventions. These include the possible use of a drive letter followed by a colon (:
), the use of backslash (\
) as the path separator, and the distinction between relative and absolute paths.
Forward slash (/
) often works when used instead of (\
) but not always; it is normally used to mark switches (options). Using forward slash can lead to various obscure behaviors, and is best avoided.
Special device names include NUL
, CON
, PRN
, AUX
, COM1
, ..., COM9
, LPT1
, ..., LPT9
; these can be redirected to.
Examples:
attrib C:\Windows\System32\notepad.exe
- Succeeds if the file exists, as it should. This is an absolute path with a drive letter. It is also known as a fully qualified path.
attrib \Windows\System32\notepad.exe
- Succeeds if the current drive is
C:
, and if the file exists, as it should. This is an absolute path without a drive letter.
- Succeeds if the current drive is
cd /d C:\Windows & attrib System32\notepad.exe
- Succeeds if the file exists. The path given to
attrib
is a relative path.
- Succeeds if the file exists. The path given to
cd /d C:\Windows\System32 & attrib C:notepad.exe
- Succeeds if the file exists. The path given to
attrib
is a one despite containing a drive letter: there would have to beC:\notepad.exe
with a backslash for that to be an absolute path.relative
- Succeeds if the file exists. The path given to
cd /d C:\Windows & attrib .\System32\notepad.exe
- Succeeds if the file exists. A single period denotes the current folder.
attrib .
- A single period denotes the current folder.
cd /d C:\Windows & attrib .\System32\\\notepad.exe
- Succeeds if the file exists. Piling of backslashes has no impact beyond the first backslash.
cd /d C:\Windows & attrib .\System32
- Succeeds if the folder exists.
cd /d C:\Windows & attrib .\System32\
- Fails. Folders are usually denoted without the final backslash.
cd C:\Windows\System32\
- Succeeds.
cd ..
- A double period denotes the parent folder.
attrib C:\Windows\System32\..\..\Windows\System32
- A double period can be used in the middle of the path to navigate to the parent folder, even multiple times.
attrib \\myserver\myvolume
- A network UNC path starts with double backslash and no drive letter.
cd \\myserver\myvolume
- Does not work; changing to a server folder in this direct manner does not work.
pushd \\myserver\folder
- Automatically creates a drive for the folder and changes to it. After you use POPD, the drive gets unassigned again.
attrib C:/Windows/System32/notepad.exe
- Succeeds on multiple versions of
cmd.exe
. Uses forward slashes.
- Succeeds on multiple versions of
Links:
- Long filenames, NTFS and legal filename characters at ss64.com
- Naming Files, Paths, and Namespaces at Microsoft
- W:Path (computing)#MS-DOS/Microsoft Windows style, wikipedia.org
- Why does the cmd.exe shell on Windows fail with paths using a forward-slash ('/) path separator
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents