This article needs additional citations for verification. (July 2008) (Learn how and when to remove this template message)
A path, the general form of the name of a file or directory, specifies a unique location in a file system. A path points to a file system location by following the directory tree hierarchy expressed in a string of characters in which path components, separated by a delimiting character, represent each directory. The delimiting character is most commonly the slash ("/"), the backslash character ("\"), or colon (":"), though some operating systems may use a different delimiter. Paths are used extensively in computer science to represent the directory/file relationships common in modern operating systems, and are essential in the construction of Uniform Resource Locators (URLs). Resources can be represented by either absolute or relative paths.
- 1 History
- 2 Absolute and relative paths
- 3 Representations of paths by operating system and shell
- 4 Paths in programming languages
- 5 Universal Naming Convention
- 6 POSIX pathname definition
- 7 Example
- 8 Misconceptions
- 9 See also
- 10 References
- 11 External links
Around 1970, Unix introduced the slash character ("/") as its directory separator.
In 1981, the first version of Microsoft DOS was released. MS-DOS 1.0 did not support file directories. Also, a major portion of the utility commands packaged with MS-DOS 1.0 came from IBM and their command line syntax used the slash character as a 'switch' prefix. For example,
dir /w runs the
dir command with the wide list format option.
This use of slash can still be found in the command interface under Microsoft Windows. By contrast, Unix uses the dash ("-") character as a command line switch prefix.
When directory support was added to MS-DOS in version 2.0, "/" was kept as the switch prefix character for backwards compatibility. Microsoft chose the backslash character ("\") as a directory separator, which looks similar to the slash character.
Absolute and relative paths
By contrast, a relative path starts from some given working directory, avoiding the need to provide the full absolute path. A filename can be considered as a relative path based at the current working directory. If the working directory is not the file's parent directory, a file not found error will result if the file is addressed by its name.
Representations of paths by operating system and shell
|Operating System||Shell||Root Directory||Directory Separator||Current Directory||Parent Directory||Home Directory||Examples|
|Microsoft Windows||Windows PowerShell||
|Classic Mac OS||
|AmigaOS||Amiga CLI / AmigaShell||
note: &, % and @ can also be used to reference the root of the current user, the library and the current (working) directory respectively.
|Symbian OS||File manager||
|Stratus VOS||VOS command-line interpreter||
|NonStop Kernel||TACL Tandem Advanced Command Language||No root||
||No parent directory|
||no subdirectories||no subdirectories||no parent||no subdirectories|
note: prefix may be a number (0-31),
Japanese and Korean versions of Windows may often display the '¥' character or the '₩' character instead of the directory separator. In such cases the code for a backslash is being drawn as these characters. Very early versions of MS-DOS replaced the backslash with these glyphs on the display to make it possible to display them by programs that only understood 7-bit ASCII (other characters such as the square brackets were replaced as well, see ISO 646, Windows Codepage 932 (Japanese Shift JIS), and Codepage 949 (Korean)). Although even the first version of Windows supported the 8-bit ISO-8859-1 character set which has the Yen sign at U+00A5, and modern versions of Windows supports Unicode which has the Won sign at U+20A9, much software will continue to display backslashes found in ASCII files this way to preserve backwards compatibility.
Mac OS X, as a derivative of UNIX, uses UNIX paths internally. However, to preserve compatibility for software and familiarity for users, many portions of the GUI switch "/" typed by the user to ":" internally, and switch them back when displaying filenames (a ":" entered by the user is also changed into "/" but the inverse translation does not happen).
Paths in programming languages
Programming languages also use paths. E.g.: When a file is opened. Most programming languages use the path representation of the underlying operating system:
uxFile = fopen("project/readme.txt", "r")
winFile = fopen("C:\Program Files\bin\config.bat", "r")
This direct access to the operating system paths can hinder the portability of programs. To support portable programs Java uses File.separator to distinguish between / and \ separated paths. Seed7 has a different approach for the path representation. In Seed7 all paths use the Unix path convention, independent of the operating system. Under windows a mapping takes place (e.g.: The path /c/users is mapped to c:\users).
Universal Naming Convention
The Microsoft Windows UNC, short for Universal Naming Convention or Uniform Naming Convention, specifies a common syntax to describe the location of a network resource, such as a shared file, directory, or printer. The UNC syntax for Windows systems has the generic form:
Microsoft often refers to this as a "network path".
Some Microsoft Windows interfaces also allow or require UNC syntax for WebDAV share access, rather than a URL. The UNC syntax is extended with optional components to denote use of SSL and TCP/IP port number, a WebDAV URL of
When viewed remotely, the "SharedFolder" may have a name different from what a program on the server sees when opening "\SharedFolder". Instead, the SharedFolder name consists of an arbitrary name assigned to the folder when defining its "sharing".
Some Microsoft Windows interfaces also accept the "Long UNC":
Microsoft Windows uses the following types of paths:
- local file system (LFS), such as
- universal naming convention (UNC), such as
<internet resource name>[\Directory name](at least in Windows 7 and later)
- "long" device path, such as
In versions of Windows prior to Windows XP, only the APIs that accept "long" device paths could accept more than 260 characters.
Since UNCs start with two backslashes, and the backslash is also used for string escaping and in regular expressions, this can result in extreme cases of leaning toothpick syndrome: an escaped string for a regular expression matching a UNC begins with 8 backslashes –
\\\\\\\\ – because the string and regular expression both require escaping. This can be simplified by using raw strings, as in C#'s
@"\\\\" or Python's
r'\\\\', or regular expression literals, as in Perl's
POSIX pathname definition
Most Unix-like systems use a similar syntax. POSIX allows treating a path beginning with two slashes in an implementation-defined manner, though in other cases systems must treat multiple slashes as single slashes. Many applications on Unix-like systems (for example, scp, rcp and rsync) use resource definitions such as:
or like URLs with the service name (here 'smb'):
Attached to a current working directory (cwd) of:
One wants to change the current working directory to:
At that moment, the relative path for the desired directory can be represented as:
or for short:
and the absolute path for the directory as:
Given bobapples as the relative path for the directory wanted, the following may be typed at the command prompt to change the current working directory to bobapples:
Two dots ("..") point upwards in the hierarchy, to indicate the parent directory; one dot (".") represents the current directory itself. Both can be components of a complex relative path (e.g., "../mark/./bobapples"), where "." alone or as the first component of such a relative path represents the working directory. (Using "./foo" to refer to a file "foo" in the current working directory can sometimes usefully distinguish it from a resource "foo" to be found in a default directory or by other means; for example, to view a specific version of a manual page instead of the one installed in the system.)
MS-DOS/Microsoft Windows style
Contrary to popular belief, the Windows system API accepts slash, and thus all the above Unix examples should work. But many applications on Windows interpret a slash for other purposes or treat it as an invalid character, and thus require you to enter backslash — notably the cmd.exe shell (often called the "terminal" as it typically runs in a terminal window). Note that many other shells available for Windows, such as tcsh and Windows PowerShell, allow the slash.
In addition "\" does not indicate a single root, but instead the root of the "current disk". Indicating a file on a disk other than the current one requires prefixing a drive letter and colon. No ambiguity ensues, because colon is not a valid character in an MS-DOS filename, and thus one cannot have a file called "A:" in the current directory.
UNC names (any path starting with \\?\) do not support slashes.
This path points to a file with the name File.txt, located in the directory Temp, which in turn is located in the root directory of the drive A:.
This path refers to a file called File.txt located in the parent directory of the current directory on drive C:.
This path denotes a file called File.txt located in SubFolder directory which in turn is located in Folder directory which is located in the current directory of the current drive (since this example gives no drive-specification).
This rather simple path points to a file named
File.txt located in the current directory (since the path lacks a directory-specification) on the current drive (since no drive specification is present).
C:\>more < C:/Windows/system.ini
; for 16-bit app support [386Enh] woafont=dosapp.fon EGA80WOA.FON=EGA80WOA.FON EGA40WOA.FON=EGA40WOA.FON CGA80WOA.FON=CGA80WOA.FON CGA40WOA.FON=CGA40WOA.FON ...
This example uses a path containing slashes as directory separator. The command redirects the content of the file to the
E:\>dir "/Folder/SubFolder/" /Q Volume in drive E is Data Volume Serial Number is 07BE-0B10 Directory of E:\Folder\SubFolder 18 October 2008 08:15 AM <DIR> DOMAIN\user . 18 October 2008 08:15 AM <DIR> DOMAIN\user .. 18 October 2008 08:15 AM <DIR> DOMAIN\user File.txt 1 File(s) 8 bytes 2 Dir(s) 19,063,000 bytes free
A path containing forward slashes often needs to be surrounded by double quotes to disambiguate it from command line switches.
- note: CD does not work this way:
CD "[drive letter]:/Program Files" will only work from the root ([drive letter]:\) directory. This appears to treat all forward slashes the same as .\.
- exception: Use the /D switch to change current drive in addition to changing current directory for a drive.
CD "C:.\Program Files"
works the same as
CD "C:/Program Files"
Also, from a root folder:
CD "C:.\Program Files.\Internet Explorer"
would be treated the same as
CD "C:/Program Files/Internet Explorer"
If there is no relative path to the directory name specified with forward slashes you will get the following error:
The system cannot find the path specified.
For setting environment variables, it is sometimes necessary to provide a path that does not contain spaces in it, for instance
%JAVA_HOME% defined as "C:\Program Files\Java..." can cause scripts to halt when they encounter the space in the path name. To get the eight-character name Windows assigns to any directory for substitution in environment variables, use the directory listing command with the /x option one level up from the target directory. For instance, the following will get you the eight character name for all directories directly under root:
The correct way to represent a path as a directory is with a trailing slash and a period.
We might think that paths that end in a trailing slash are directories. But in actuality, a path ending in a trailing slash represents all files within the directory.
is simply a path to a file which may or may not be a directory. It is not a path to a directory. Even if it may eventually resolve to a directory.
- Device file
- Distributed file system (DFS)
- Filesystem Hierarchy Standard (FHS)
- Fully qualified file name
- PATH (variable)
- Uniform Resource Locator (URL)
- Daley, R.C.; Neumann, P.G. (1965). "A general-purpose file system for secondary storage". AFIPS Proceedings of the joint computer conference. Part I: 213–229. doi:10.1145/1463891.1463915.
- "cd". Windows Commands : Windows Server. Microsoft Docs. Retrieved 14 July 2019.
- Sorting it all Out: When is a backslash not a backslash?
- "DavGetHTTPFromUNCPath function". WebDAV : Windows. Microsoft Docs. series. Retrieved 14 July 2019.
- "File path formats on Windows systems". File and Stream I/O : .NET. Microsoft Docs. Retrieved 14 July 2019.
- UNC Definition by ComputerLanguage.com
- POSIX pathname resolution specification
- POSIX pathname definition
- "Naming Files, Paths, and Namespaces". Local File Systems : Windows. Microsoft Docs. Retrieved 14 July 2019.
- Path Definition - The Linux Information Project (LINFO)
- Naming Files, Paths, and Namespaces - Local File Systems : Windows : Microsoft Docs