HOME

TheInfoList



OR:

A path (or filepath, file path, pathname, or similar) is a text string that uniquely specifies an item in a
hierarchical file system In computing, a hierarchical file system is a file system that uses directories to organize files into a tree structure. In a hierarchical file system, ''directories'' contain information about both files and other directories, called ''sub ...
. Generally, a path is composed of directory names, special directory specifiers and optionally a
filename 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 ...
, separated by delimiting text. The delimiter varies by operating system and in theory can be anything, but popular, modern systems use
slash Slash may refer to: * Slash (punctuation), the "/" character Arts and entertainment Fictional characters * Slash (Marvel Comics) * Slash (''Teenage Mutant Ninja Turtles'') Music * Harry Slash & The Slashtones, an American rock band * Nash th ...
,
backslash The backslash is a mark used mainly in computing and mathematics. It is the mirror image of the common slash (punctuation), slash . It is a relatively recent mark, first documented in the 1930s. It is sometimes called a hack, whack, Escape c ...
, or colon . A path can be either relative or absolute. A relative path includes information that is relative to a particular directory whereas an absolute path indicates a location relative to the system
root directory In a Computing, computer file system, and primarily used in the Unix and Unix-like operating systems, the root directory is the first or top-most Directory (computing), directory in a hierarchy. It can be likened to the trunk of a Tree (data st ...
, and therefore, does not depends on context like a relative path does. Often, a relative path is relative to the
working directory In computing, the working directory of a process is a directory of a hierarchical file system, if any, dynamically associated with the process. It is sometimes called the current working directory (CWD), e.g. the BSD getcwd function, or just c ...
. For example, in command , is a relative path to the file with that name in the working directory. Paths are used extensively in
computer science Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
to represent the directory/file relationships common in modern operating systems and are essential in the construction of uniform resource locators (URLs).


History

Multics Multics ("MULTiplexed Information and Computing Service") is an influential early time-sharing operating system based on the concept of a single-level memory.Dennis M. Ritchie, "The Evolution of the Unix Time-sharing System", Communications of t ...
first introduced a
hierarchical file system In computing, a hierarchical file system is a file system that uses directories to organize files into a tree structure. In a hierarchical file system, ''directories'' contain information about both files and other directories, called ''sub ...
with directories (separated by ">") in the mid-1960s. Around 1970,
Unix Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
introduced the slash character ("/") as its directory separator. Originally,
MS-DOS MS-DOS ( ; acronym for Microsoft Disk Operating System, also known as Microsoft DOS) is an operating system for x86-based personal computers mostly developed by Microsoft. Collectively, MS-DOS, its rebranding as IBM PC DOS, and a few op ...
did not support directories, but when adding the feature, using the Unix standard of slash was not a good option since many existing commands used slash as the
switch In electrical engineering, a switch is an electrical component that can disconnect or connect the conducting path in an electrical circuit, interrupting the electric current or diverting it from one conductor to another. The most common type o ...
prefix. For example, 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
Windows Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
in its shell
Command Prompt A command-line interface (CLI) is a means of interacting with software via commands each formatted as a line of text. Command-line interfaces emerged in the mid-1960s, on computer terminals, as an interactive and more user-friendly alternativ ...
. Eventually,
PowerShell PowerShell is a shell program developed by Microsoft for task automation and configuration management. As is typical for a shell, it provides a command-line interpreter for interactive use and a script interpreter for automation via a langu ...
, was introduced to Windows that is slash-agnostic, allowing the use of either slash in a path.


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 '
â‚© The won sign , is a currency symbol. It represents the South Korean won, the North Korean won and, unofficially, the old Korean Empire won, Korean won. Appearance Its appearance is "W" (the first letter of "Won") with a horizontal strike ...
' 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 ASCII ( ), an acronym for American Standard Code for Information Interchange, is a character encoding standard for representing a particular set of 95 (English language focused) printable character, printable and 33 control character, control c ...
(other characters such as the square brackets were replaced as well, see
ISO 646 ISO/IEC 646 ''Information technology â€” ISO 7-bit coded character set for information interchange'', is an International Organization for Standardization, ISO/International Electrotechnical Commission, IEC standard in the ...

Windows Codepage 932 (Japanese Shift JIS)
an

. Although even the first version of Windows supported the 8-bit
ISO-8859-1 ISO/IEC 8859-1:1998, ''Information technology—8-bit computing, 8-bit single-byte coded graphic character (computing), character sets—Part 1: Latin alphabet No. 1'', is part of the ISO/IEC 8859 series of ASCII-based standard character enc ...
character set which has the Yen sign at U+00A5, and modern versions of Windows supports
Unicode Unicode or ''The Unicode Standard'' or TUS is a character encoding standard maintained by the Unicode Consortium designed to support the use of text in all of the world's writing systems that can be digitized. Version 16.0 defines 154,998 Char ...
which has the Won sign at U+20A9, much software will continue to display backslashes found in ASCII files this way to preserve backward compatibility.
macOS macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
, 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 Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
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 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 for
WebDAV WebDAV (Web Distributed Authoring and Versioning) is a set of extensions to the Hypertext Transfer Protocol (HTTP), which allows user agents to collaboratively author contents ''directly'' in an HTTP web server by providing facilities for conc ...
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 http //HostName
Port 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/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, 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: 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 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 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