Template:Short description Template:For Template:More citations needed Template:Use dmy dates A path (or filepath, file path, pathname, or similar) is a text string that uniquely specifies an item in a hierarchical file system. Generally, a path is composed of directory names, special directory specifiers and optionally a filename, separated by delimiting text. The delimiter varies by operating system and in theory can be anything, but popular, modern systems use slash <syntaxhighlight lang="text" class="" style="" inline="1">/</syntaxhighlight>, backslash <syntaxhighlight lang="text" class="" style="" inline="1">\</syntaxhighlight>, or colon <syntaxhighlight lang="text" class="" style="" inline="1">:</syntaxhighlight>.

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, and therefore, does not depends on context like a relative path does. Often, a relative path is relative to the working directory. For example, in command <syntaxhighlight lang="text" class="" style="" inline="1">ls f</syntaxhighlight>, <syntaxhighlight lang="text" class="" style="" inline="1">f</syntaxhighlight> is a relative path to the file with that name in the working directory.

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).

HistoryEdit

Multics first introduced a hierarchical file system with directories (separated by ">") in the mid-1960s.<ref>Template:Cite conference</ref>

Around 1970, Unix introduced the slash character ("/") as its directory separator.

Originally, MS-DOS 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 prefix. For example, dir /w. In contrast, Unix uses dash <syntaxhighlight lang="text" class="" style="" inline="1">-</syntaxhighlight> as the switch prefix. In this context, MS-DOS version 2.0 used backslash <syntaxhighlight lang="text" class="" style="" inline="1">\</syntaxhighlight> for the path delimiter since it is similar to slash but did not conflict with existing commands. This convention continued into Windows in its shell Command Prompt. Eventually, PowerShell, was introduced to Windows that is slash-agnostic, allowing the use of either slash in a path.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

Path syntaxEdit

The following table describes the syntax of paths in notable operating systems and with notable aspects by shell.

Template:Table alignment

Context Root
dir
Path
delim
Working
dir
Parent
dir
Home
dir
Examples
Unix / / . .. ~ /home/user/docs/Letter.txt
./inthisdir
../../greatgrandparent
~/.rcinfo
DOS COMMAND.COM [drive letter:]\
or \\[server name]\[volume]\
\ . .. C:\USER\DOCS\LETTER.TXT
A:PICTURE.JPG
\\SERVER01\USER\DOCS\LETTER.TXT
OS/2 cmd.exe [drive letter:]\
or \\[server name]\[volume]\
/
or
\
. .. C:\user\docs\Letter.txt
A:Picture.jpg
\\SERVER01\USER\docs\Letter.txt
Windows Command Prompt citation CitationClass=web

}}</ref>

/
or
\
. citation CitationClass=web

}}</ref>

C:\user\docs\Letter.txt
/user/docs/Letter.txt
C:\Letter.txt
\\Server01\user\docs\Letter.txt
\\?\UNC\Server01\user\docs\Letter.txt
\\?\C:\user\docs\Letter.txt
C:\user\docs\somefile.ext:alternate stream name
./inthisdir
../../greatgrandparent
Windows PowerShell [drive letter:]/
or [drive name:]\
or \\[server name]\
or [PSSnapIn name]\[PSProvider name:][:PSDrive root]
/
or
\
. .. ~ C:\user\docs\Letter.txt
C:\user/docs\Letter.txt
\\Server01\user\docs\Letter.txt
cd ~\Desktop

UserDocs:/Letter.txt
Variable:PSVersionTable
Registry::HKEY_LOCAL_MACHINE\SOFTWARE\
Microsoft.PowerShell.Security\Certificate::CurrentUser\

TOPS-20 DCL [device name:] . PS:<USER.DOCS>LETTER.TXT,4
RSX-11 MCR [device name:] DR0:[30,12]LETTER.TXT;4
OpenVMS DCL [device name:][000000]
or [NODE["accountname password"]]::[device name][000000]:
. [] [-] SYS$LOGIN: SYS$SYSDEVICE:[USER.DOCS]PHOTO.JPG

[]IN_THIS_DIR.COM;
[-.-]GreatGrandParent.TXT
SYS$SYSDEVICE:[.DRAFTS]LETTER.TXT;4
GEIN::[000000]LETTER.TXT;4
SYS$LOGIN:LOGIN.COM

Classic
Mac OS
[volume or drive name]: : : :: Macintosh HD:Documents:Letter
:fileincurrentdir
::fileinparent
:::fileingrandparent
ProDOS AppleSoft BASIC /[volume or drive name]/ / /SCHOOL.DISK/APPLEWORKS/MY.REPORT

FLIGHT.SIMULATOR,D2

AmigaOS Amiga CLI /
AmigaShell
[drive, volume, device, or assign name]: / empty
string
/ Workbench:Utilities/MultiView
DF0:S/Startup-Sequence
S:Startup-Sequence
TCP:en.wikipedia.com/80
RISC OS ShellCLI [fs type[#option]:][:drive number or disc name.]$

note: &, %, and @ can also be used to reference the root
of the current user, the library and the current (working) directory respectively.

. @ ^ & ADFS::MyDrive.$.Documents.Letter
Net#MainServer::DataDrive.$.Main.sy10823
LanMan::WindowsC.$.Pictures.Japan/gif
NFS:&.!Choices
ADFS:%.IfThere
@.inthisdir
^.^.greatgrandparent

When filesystems with filename extensions are mounted,
'.' characters are changed to '/', as in the Japan/gif example above.

Symbian OS File manager \ \ \user\docs\Letter.txt
Domain/OS Shell

// (root of domain)
/ (root of current node)

/ . \ ~ //node/home/user/docs/Letter.txt
./inthisdir
\\greatgrandparent
~rcinfo
MenuetOS CMD / /
Stratus VOS VOS command-line
interpreter
%[system_name]#[module_name]> > < %sysname#module1>SubDir>AnotherDir
NonStop
Kernel
TACL
Tandem Advanced
Command Language
No root . none \NODE.$DISK.SUBVOL.FILE
\NODE.$DEVICE
\NODE.$DEVICE.#SUBDEV.QUALIFIER
CP/M CCP [drive letter:] no directory support, just user areas 0–F A:LETTER.TXT
GS/OS :[volume name]: or .[device name]: or [prefix]:

note: prefix may be a number (0–31), * (boot volume) or @ (AppleShare home directory)

:
or
/
@ :Apps:Platinum.Paint:Platinum.Paint
*:System:Finder
.APPLEDISK3.5B/file
OpenHarmony (incl. HarmonyOS) exec<ref>{{#invoke:citation/CS1|citation CitationClass=web

}}</ref><ref>{{#invoke:citation/CS1|citation

CitationClass=web

}}</ref>

hb set -root [ROOT_PATH]

hb set -p --product [PRODUCT_NAME]

> ./ ../ LOCAL>MEDIA_TYPE_>Download>Letter.txt

Japanese and Korean versions of Windows 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 backward compatibility.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

macOS, 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 languagesEdit

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 ConventionEdit

Template:Anchor 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 share access, rather than a URL. The UNC syntax is extended<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> with optional components to denote use of SSL and TCP/IP port number, a WebDAV URL of http[s]://HostName[:Port]/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 /<internet resource name>[\Directory name] (at least in Windows 7 and later)
  • "long" device path such as \\?\C:\File or \\?\UNC\Server\Volume\File.<ref name="netpaths">{{#invoke:citation/CS1|citation

|CitationClass=web }}</ref> This path points to the local file namespace and <syntaxhighlight lang="text" class="" style="" inline="1">\\.\</syntaxhighlight> 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 Template:Mono to Template:Mono and interpreting names like Template:Mono.<ref name="w32paths" />

|CitationClass=web }}</ref><ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

In versions of Windows prior to Windows XP, only the APIs that accept "long" device paths could accept more than 260 characters.

The shell in Windows XP and Windows Vista, explorer.exe, allows path names up to 248 characters long.Template:Citation needed

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 qr{\\\\}.

POSIX pathname definitionEdit

Most Unix-like systems use a similar syntax.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> POSIX allows treating a path beginning with two slashes in an implementation-defined manner,<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> though in other cases systems must treat multiple slashes as single slashes.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> Many applications on Unix-like systems (for example, scp, rcp, and rsync) use resource definitions such as:

hostname:/directorypath/resource

or URI schemes with the service name (here 'smb'):

smb://hostname/directorypath/resource

ExamplesEdit

UnixEdit

The following examples are for typical, Unix-based file systems:

Given the working directory is <syntaxhighlight lang="text" class="" style="" inline="1">/home/mark/</syntaxhighlight> and it contains subdirectory <syntaxhighlight lang="text" class="" style="" inline="1">bobapples</syntaxhighlight>, relative paths to the subdirectory include <syntaxhighlight lang="text" class="" style="" inline="1">./bobapples</syntaxhighlight> and <syntaxhighlight lang="text" class="" style="" inline="1">bobapples</syntaxhighlight>, and the absolute path is <syntaxhighlight lang="text" class="" style="" inline="1">/home/mark/bobapples</syntaxhighlight>. A command to change the working directory to the subdirectory:

<syntaxhighlight lang="console> $ cd bobapples </syntaxhighlight>

If the working directory was <syntaxhighlight lang="text" class="" style="" inline="1">/home/jo</syntaxhighlight>, then the relative path <syntaxhighlight lang="text" class="" style="" inline="1">../mark/bobapples</syntaxhighlight> specifies the subdirectory. The double dots <syntaxhighlight lang="text" class="" style="" inline="1">..</syntaxhighlight> indicates a move up the directory hierarchy one level to <syntaxhighlight lang="text" class="" style="" inline="1">/home</syntaxhighlight>, the rest indicates moving down to <syntaxhighlight lang="text" class="" style="" inline="1">mark</syntaxhighlight> and then <syntaxhighlight lang="text" class="" style="" inline="1">boapples</syntaxhighlight>.

Microsoft shellsEdit

Template:More citations needed section

File:Dir command in Windows Command Prompt.png
Screenshot of a Windows Command Prompt shell showing filenames in a directory

The Windows API 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 <syntaxhighlight lang="text" class="" style="" inline="1">\\?\</syntaxhighlight>) does not support slashes.<ref name="w32paths" />

A:\Temp\File.txt is an absolute path that specifies a file named <syntaxhighlight lang="text" class="" style="" inline="1">File.txt</syntaxhighlight> in the directory <syntaxhighlight lang="text" class="" style="" inline="1">Temp</syntaxhighlight> which is in the root of drive <syntaxhighlight lang="text" class="" style="" inline="1">A:</syntaxhighlight>:

C:..\File.txt is a relative path that specifies file <syntaxhighlight lang="text" class="" style="" inline="1">File.txt</syntaxhighlight> located in the parent of the working directory on drive <syntaxhighlight lang="text" class="" style="" inline="1">C:</syntaxhighlight>:

Folder\SubFolder\File.txt is a relative path that specifies file <syntaxhighlight lang="text" class="" style="" inline="1">File.txt</syntaxhighlight> in directory <syntaxhighlight lang="text" class="" style="" inline="1">SubFolder</syntaxhighlight> which is in directory <syntaxhighlight lang="text" class="" style="" inline="1">Folder</syntaxhighlight> 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, COM1:

The following uses a path with slashes for directory delimiter:

<syntaxhighlight lang="doscon"> 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 ... </syntaxhighlight>

A path with forward slashes may need to be surrounded by double quotes to disambiguate from command-line switches. For example, <syntaxhighlight lang="text" class="" style="" inline="1">dir /windows</syntaxhighlight> is invalid, but <syntaxhighlight lang="text" class="" style="" inline="1">dir "/window"</syntaxhighlight> is valid. And <syntaxhighlight lang="text" class="" style="" inline="1">cd</syntaxhighlight> is more lenient by allowing <syntaxhighlight lang="text" class="" style="" inline="1">cd /windows</syntaxhighlight>.

See alsoEdit

ReferencesEdit

Template:Reflist

External linksEdit

Template:Computer files