History
dir /w
. In contrast, Unix uses dash as the switch prefix. In this context, MS-DOS version 2.0 used backslash for the path delimiter since it is similar to slash but did not conflict with existing commands. This convention continued into Path syntax
The following table describes the syntax of paths in notable operating systems and with notable aspects by shell. Japanese and Korean versions of Windows often display the ' ¥' character or the '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 Universal Naming Convention
The Microsoft universal naming convention (UNC), a.k.a. uniform naming convention, a.k.a. network path, specifies a syntax to describe the location of a network resource, such as a shared file, directory, or printer. A UNC path has the general form: \\ComputerName\SharedFolder\Resource Some Windows interfaces allow or require UNC syntax forhttp //HostNamePort
A port is a maritime facility comprising one or more wharves or loading areas, where ships load and discharge cargo and passengers. Although usually situated on a sea coast or estuary, ports can also be found far inland, such as Hamburg, Manch ...
SharedFolder/Resource
becomes
\\HostName SSL@Port]\SharedFolder\Resource
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 Windows interfaces also accept the "Long UNC":
\\?\UNC\ComputerName\SharedFolder\Resource
Windows uses the following types of paths:
* local file system (LFS), such as C:\File
* universal naming convention (UNC), such as \\Server\Volume\File
or /Directory name
A filename or file name is a name used to uniquely identify a computer file in a file system. Different file systems impose different restrictions on filename lengths.
A filename may (depending on the file system) include:
* name – base ...
/code> (at least in Windows 7 and later)
* "long" device path such as \\?\C:\File
or \\?\UNC\Server\Volume\File
. This path points to the local file namespace and is a similar one that points to the local DOS device namespace. This format is also the "raw" or "uninterpreted" path, since it sends paths straight to the file system without converting to and interpreting names like .
* Windows NT object manager \\??\
-prefixed paths (global DOS namespace).
In versions of Windows prior to Windows XP, only the APIs that accept "long" device paths could accept more than 260 characters.
The shell
Shell may refer to:
Architecture and design
* Shell (structure), a thin structure
** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses
Science Biology
* Seashell, a hard outer layer of a marine ani ...
in Windows XP
Windows XP is a major release of Microsoft's Windows NT operating system. It was released to manufacturing on August 24, 2001, and later to retail on October 25, 2001. It is a direct successor to Windows 2000 for high-end and business users a ...
and Windows Vista
Windows Vista is a major release of the Windows NT operating system developed by Microsoft. It was the direct successor to Windows XP, released five years earlier, which was then the longest time span between successive releases of Microsoft W ...
, explorer.exe
File Explorer, previously known as Windows Explorer, is a file manager application and default desktop environment that is included with releases of the Microsoft Windows operating system from Windows 95 onwards. It provides a graphical user i ...
, allows path names up to 248 characters long.
Since UNCs start with two backslashes, and the backslash is also used for string escaping and in regular expression
A regular expression (shortened as regex or regexp), sometimes referred to as rational expression, is a sequence of characters that specifies a match pattern in text. Usually such patterns are used by string-searching algorithms for "find" ...
s, this can result in extreme cases of leaning toothpick syndrome
In computer programming, leaning toothpick syndrome (LTS) is the situation in which a quoted expression becomes unreadable because it contains a large number of escape characters, usually backslashes ("\"), to avoid delimiter collision.
The offici ...
: 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 string
string literal or anonymous string is a literal for a string value in the source code of a computer program. Modern programming languages commonly use a quoted sequence of characters, formally "bracketed delimiters", as in x = "foo", where , "foo ...
s, as in C#'s @"\\\\"
or Python's r'\\\\'
, or regular expression literals, as in Perl's qr
.
POSIX pathname definition
Most Unix-like systems use a similar syntax.
POSIX
The Portable Operating System Interface (POSIX; ) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines application programming interfaces (APIs), along with comm ...
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
rsync (remote sync) is a utility for transferring and synchronizing files between a computer and a storage drive and across networked computers by comparing the modification times and sizes of files. It is commonly found on Unix-like opera ...
) use resource definitions such as:
hostname:/directorypath/resource
or URI
Uri may refer to:
Places
* Canton of Uri, a canton in Switzerland
* Úri, a village and commune in Hungary
* Uri, Iran, a village in East Azerbaijan Province
* Uri, Jammu and Kashmir, a town in India
* Uri (island), off Malakula Island in V ...
schemes with the service name (here 'smb'):
smb://hostname/directorypath/resource
Examples
Unix
The following examples are for typical, Unix-based file systems:
Given the working directory is and it contains subdirectory , relative paths to the subdirectory include and , and the absolute path is . A command to change the working directory to the subdirectory:
The Windows API
The Windows API, informally WinAPI, is the foundational application programming interface (API) that allows a computer program to access the features of the Microsoft Windows operating system in which the program is running. Programs can acces ...
accepts slash for path delimiter.
Unlike Unix that always has a single root directory, a Windows file system has a root for each storage drive. An absolute path includes a drive letter or uses the UNC format.
A UNC path (starting with ) does not support slashes.
A:\Temp\File.txt
is an absolute path that specifies a file named in the directory which is in the root of drive :
C:..\File.txt
is a relative path that specifies file located in the parent of the working directory on drive :
Folder\SubFolder\File.txt
is a relative path that specifies file in directory which is in directory which is in the working directory of the current drive:
File.txt
is a relative path that specifies File.txt
in the working directory:
\\.\COM1
specifies the first serial port
A serial port is a serial communication Interface (computing), interface through which information transfers in or out sequentially one bit at a time. This is in contrast to a parallel port, which communicates multiple bits simultaneously in Pa ...
, COM1:
The following uses a path with slashes for directory delimiter:
C:\>more < C:/Windows/system.ini
; for 16-bit app support
86Enhwoafont=dosapp.fon
EGA80WOA.FON=EGA80WOA.FON
EGA40WOA.FON=EGA40WOA.FON
CGA80WOA.FON=CGA80WOA.FON
CGA40WOA.FON=CGA40WOA.FON
...
A path with forward slashes may need to be surrounded by double quotes to disambiguate from command-line switches. For example, is invalid, but is valid. And is more lenient by allowing .
See also
*
*
*
*
*
*
*
*
*
References
External links
Path Definition
- The Linux Information Project (LINFO)
Naming Files, Paths, and Namespaces
- Local File Systems: Windows: Microsoft Docs
Microsoft Docs was a library of technical documentation for end users, developers, and IT professionals who work with Microsoft products. The Microsoft Docs website provided technical specifications, conceptual articles, tutorials, guides, API ...
{{Computer files
Computer file systems