Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Path (computing)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Text that specifies a file system item in a directory structure}} {{For|the environment variable|PATH (variable)}} {{More citations needed|date=July 2008}} {{Use dmy dates|date=March 2020}} A '''path''' (or '''filepath''', '''file path''', '''pathname''', or similar) is a [[string (computer science)|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 [[delimiter|delimiting text]]. The delimiter varies by operating system and in theory can be anything, but popular, modern systems use [[slash (punctuation)|slash]] {{code|/}}, [[backslash]] {{code|\}}, or colon {{code|:}}. 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 {{code|ls f}}, {{code|f}} 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 locator|uniform resource locators]] (URLs). ==History== [[Multics]] first introduced a [[hierarchical file system]] with directories (separated by ">") in the mid-1960s.<ref>{{cite conference |last1=Daley |first1=R.C. |last2=Neumann |first2=P.G. |book-title=Proceedings of the November 30--December 1, 1965, fall joint computer conference, Part I on XX - AFIPS '65 (Fall, part I) |title=A general-purpose file system for secondary storage |date=1965 |volume=Part I |pages=213β229 |doi=10.1145/1463891.1463915 |doi-access=free |s2cid=16236414}}</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 [[command-line switch|switch]] prefix. For example, <code>dir /w</code>. In contrast, Unix uses dash {{code|-}} as the switch prefix. In this context, MS-DOS version 2.0 used backslash {{code|\}} 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>{{cite web |title=Why Windows Uses Backslashes and Everything else Uses Forward Slashes |date=10 February 2014 |url=https://www.howtogeek.com/181774/why-windows-uses-backslashes-and-everything-else-uses-forward-slashes/}}</ref><ref>{{cite web |title=Why is the DOS path character ""? |url=https://learn.microsoft.com/archive/blogs/larryosterman/why-is-the-dos-path-character |date=24 June 2005}}</ref> ==Path syntax== <!-- Pathing is more a feature of the file system; not the OS or the shell, but this table focuses on OS and shell :( --> The following table describes the syntax of paths in notable operating systems and with notable aspects by shell. {{Table alignment}} {| class="wikitable col3center col4center col5center col6center" style="font-size:90%;" |- ! Context ! Root<br>dir ! Path<br>delim ! Working<br>dir ! Parent<br>dir ! Home<br>dir ! Examples |- ! [[Unix]] | <code>/</code> | <code>/</code> | <code>.</code> | <code>..</code> | <code>~</code> | <code>/home/user/docs/Letter.txt</code><br><code>./inthisdir</code><br><code>../../greatgrandparent</code><br><code>~/.rcinfo</code> |- ! [[DOS]] [[COMMAND.COM]] | <code>''[drive letter:]''\</code><br>or <code>\\''[server name]''\''[volume]''\</code> | <code>\</code> | <code>.</code> | <code>..</code> | | <code>C:\USER\DOCS\LETTER.TXT</code><br><code>A:PICTURE.JPG</code><br><code>\\SERVER01\USER\DOCS\LETTER.TXT</code> |- ! [[OS/2]] [[cmd.exe]] | <code>''[drive letter:]''\</code><br>or <code>\\''[server name]''\''[volume]''\</code> | <code>/</code><br>or<br><code>\</code> | <code>.</code> | <code>..</code> | | <code>C:\user\docs\Letter.txt</code><br><code>A:Picture.jpg</code><br><code>\\SERVER01\USER\docs\Letter.txt</code> |- ! [[Microsoft Windows|Windows]] [[Command Prompt]] | <span style="white-space:nowrap;"><code>\</code> (relative to current working directory root)</span><br>or <code>''[drive_letter]'':\</code><br>or <code style="white-space:nowrap;">\\''[server]''\''[sharename]''\</code><br>or <code style="white-space:nowrap;">\\?\''[drive_spec]'':\</code><br>or <code style="white-space:nowrap;">\\?\UNC\''[server]''\''[sharename]''\</code><br>or <code style="white-space:nowrap;">\\.\''[physical_device]''\</code><ref name="w32paths">{{cite web |title=Naming Files, Paths, and Namespaces |website=[[Microsoft Docs]] |date=15 December 2022 |url=https://learn.microsoft.com/windows/win32/fileio/naming-a-file}}</ref> | <code>/</code><br>or<br><code>\</code> | <code>.</code> | <code>..</code><ref>{{cite web |title=cd |department=Windows Commands: Windows Server |website=[[Microsoft Docs]] |date=3 February 2023 |url=https://learn.microsoft.com/windows-server/administration/windows-commands/cd |access-date=2023-10-04}}</ref> | | <code>C:\user\docs\Letter.txt</code><br><code>/user/docs/Letter.txt</code><br><code>C:\Letter.txt</code><br><code>\\Server01\user\docs\Letter.txt</code><br><code>\\?\UNC\Server01\user\docs\Letter.txt</code><br><code>\\?\C:\user\docs\Letter.txt</code><br><code><span style="white-space:nowrap;">C:\user\docs\somefile.ext:[[NTFS#Alternate data stream (ADS)|alternate stream name]]</span></code><br><code>./inthisdir</code><br><code>../../greatgrandparent</code><br> |- ! [[Windows]] [[PowerShell]] | <code>''[drive letter:]''/</code><br>or <code>''[drive name:]''\</code><br>or <code>\\''[server name]''\</code><br>or <code>''[PSSnapIn name]''\''[PSProvider name:][:PSDrive root]''</code> | <code>/</code><br>or<br><code>\</code> | <code>.</code> | <code>..</code> | <code>~</code> | <code>C:\user\docs\Letter.txt</code><br><code>C:\user/docs\Letter.txt</code><br><code>\\Server01\user\docs\Letter.txt</code><br><code>cd ~\Desktop</code><br> <code>UserDocs:/Letter.txt</code><br> <code>Variable:PSVersionTable</code><br> <code>Registry::HKEY_LOCAL_MACHINE\SOFTWARE\</code><br> <code>Microsoft.PowerShell.Security\Certificate::CurrentUser\</code> |- ! [[TOPS-20]] [[DIGITAL Command Language|DCL]] | <code>''[device name:]''</code> | <code>.</code> | | | | <code>PS:<USER.DOCS>LETTER.TXT,4</code> |- ! [[RSX-11]] MCR | <code>''[device name:]''</code> | | | | | <code>DR0:[30,12]LETTER.TXT;4</code> |- ! [[OpenVMS]] [[DIGITAL Command Language|DCL]] | <code>''[device name:]''[000000]</code><br>or <code>''[NODE["accountname password"]]''::''[device name]''[000000]:</code> | <code>.</code> | <code>[]</code> | <code>[-]</code> | <small><code>SYS$LOGIN:</code></small> | <code>SYS$SYSDEVICE:[USER.DOCS]PHOTO.JPG</code> <code>[]IN_THIS_DIR.COM;</code><br> <code>[-.-]GreatGrandParent.TXT</code><br> <code>SYS$SYSDEVICE:[.DRAFTS]LETTER.TXT;4</code><br> <code>GEIN::[000000]LETTER.TXT;4</code><br> <code>SYS$LOGIN:LOGIN.COM</code><br> |- ! [[Classic Mac OS|Classic<br>Mac OS]] | <code>''[volume or drive name]'':</code> | <code>:</code> | <code>:</code> | <code>::</code> | | <code>Macintosh HD:Documents:Letter</code><br><code>:fileincurrentdir</code><br><code>::fileinparent</code><br><code>:::fileingrandparent</code> |- ! [[Apple ProDOS|ProDOS]] AppleSoft BASIC | <code>/''[volume or drive name]''/</code> | <code>/</code> | | | | <code>/SCHOOL.DISK/APPLEWORKS/MY.REPORT</code> <code>FLIGHT.SIMULATOR,D2</code> |- ! [[AmigaOS]] Amiga CLI /<br>AmigaShell | <code>''[drive, volume, device, or assign name]:''</code> | <code>/</code> | ''empty<br>string'' | <code>/</code> | | <code>Workbench:Utilities/MultiView</code><br><code>DF0:S/Startup-Sequence</code><br><code>S:Startup-Sequence</code><br><code>TCP:en.wikipedia.com/80</code> |- ! [[RISC OS]] ShellCLI | <code>''[fs type[#option]:][:drive number or disc name.]''$</code> note: &, %, and @ can also be used to reference the root<br>of the current user, the library and the current (working) directory respectively. | <code>.</code> | <code>@</code> | <code>^</code> | <code>&</code> | <code>ADFS::MyDrive.$.Documents.Letter</code><br><code>Net#MainServer::DataDrive.$.Main.sy10823</code><br><code>LanMan::WindowsC.$.Pictures.Japan/gif</code><br><code>NFS:&.!Choices</code><br><code>ADFS:%.IfThere</code><br><code>@.inthisdir</code><br><code>^.^.greatgrandparent</code> When filesystems with filename extensions are mounted,<br>'.' characters are changed to '/', as in the Japan/gif example above. |- ! [[Symbian OS]] File manager | <code>\</code> | <code>\</code> | | | | <code>''\user\docs\Letter.txt''</code> |- ! [[Domain/OS]] Shell | <span style="white-space:nowrap;"><code>//</code> (root of domain)</span><br> <span style="white-space:nowrap;"><code>/</code> (root of current node)</span><br> | <code>/</code> | <code>.</code> | <code>\</code> | <code>~</code> | <code>//node/home/user/docs/Letter.txt</code><br><code>./inthisdir</code><br><code>\\greatgrandparent</code><br><code>~rcinfo</code> |- ! [[MenuetOS]] CMD | <code>/</code> | <code>/</code> | | | | |- ! [[Stratus VOS]] VOS command-line<br>interpreter | <code>%''[system_name]''#''[module_name]''></code> | <code>></code> | | <code><</code> | |<code>%sysname#module1>SubDir>AnotherDir</code> |- ! [[NonStop Kernel|NonStop<br>Kernel]] TACL<br>Tandem Advanced<br>Command Language | No root | <code>.</code> | | ''none'' | | <code>\NODE.$DISK.SUBVOL.FILE</code><br><code>\NODE.$DEVICE</code><br><code>\NODE.$DEVICE.#SUBDEV.QUALIFIER</code> |- ! [[CP/M]] [[Console Command Processor|CCP]] | <code>''[drive letter:]''</code> | colspan="4" | no directory support, just user areas 0βF | align="left" | <code>A:LETTER.TXT</code> |- ! [[Apple GS/OS|GS/OS]] | <code>'':[volume name]:''</code> or <code>''.[device name]:''</code> or <code>''[prefix]:''</code> note: prefix may be a number (0β31), <code>*</code> (boot volume) or <code>@</code> (AppleShare home directory) | <code>:</code><br>or<br><code>/</code> | | | <code>@</code> | <code>:Apps:Platinum.Paint:Platinum.Paint</code><br><code>*:System:Finder</code><br><code>.APPLEDISK3.5B/file</code> |- ![[OpenHarmony]] (incl. [[HarmonyOS]]) exec<ref>{{cite web |title=Introduction to the Shell |website=GitHub |publisher=OpenAtom OpenHarmony |url=https://github.com/eDorUS/OpenHarmony_docs/blob/master/en/device-dev/kernel/kernel-small-debug-shell-overview.md |access-date=13 March 2024}}</ref><ref>{{cite web |title=exec |website=GitHub |publisher=OpenAtom OpenHarmony |url=https://github.com/dashingcalico/OpenHarmony/blob/master/docs-en/kernel/exec.md |access-date=14 March 2024}}</ref> |<code>hb set -root [ROOT_PATH]</code> <code>hb set -p --product [PRODUCT_NAME]</code> |<code>></code> |<code>./</code> |<code>../</code> | |<code>LOCAL>MEDIA_TYPE_>Download>Letter.txt</code> |} Japanese and Korean versions of Windows often display the '[[Β₯]]' character or the '[[Won sign|β©]]' 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]], [https://www.microsoft.com/GLOBALDEV/Reference/dbcs/932.htm Windows Codepage 932 (Japanese Shift JIS)], and [https://www.microsoft.com/GLOBALDEV/Reference/dbcs/949.htm 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>{{cite web |website=Sorting it all Out |title=When is a backslash not a backslash? |url=http://archives.miloush.net/michkap/archive/2005/09/17/469941.html}}</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 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: <code>uxFile = fopen("project/readme.txt", "r")</code> <code>winFile = fopen("C:\\Program Files\\bin\\config.bat", "r")</code> This direct access to the operating system paths can hinder the portability of programs. To support portable programs [[Java (programming language)|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== {{Anchor|UNC}} 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>{{cite web |title=DavGetHTTPFromUNCPath function |department=WebDAV: Windows |website=[[Microsoft Docs]] |series=series |date=13 October 2021 |url=https://learn.microsoft.com/windows/win32/api/davclnt/nf-davclnt-davgethttpfromuncpath |access-date=2023-10-04}}</ref> with optional components to denote use of SSL and TCP/IP port number, a WebDAV URL of <code>http[s]://HostName[:Port]/SharedFolder/Resource</code> 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 <code>C:\File</code> * universal naming convention (UNC), such as <code>\\Server\Volume\File</code> or /<code><internet resource name>[\Directory name]</code> (at least in Windows 7 and later) * "long" device path such as <code>\\?\C:\File</code> or <code>\\?\UNC\Server\Volume\File</code>.<ref name="netpaths">{{cite web |title=File path formats on Windows systems |department=File and Stream I/O: .NET |website=[[Microsoft Docs]] |url=https://learn.microsoft.com/dotnet/standard/io/file-path-formats |access-date=2019-07-14}}</ref> This path points to the local file namespace and {{code|\\.\}} 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 {{mono|/}} to {{mono|\}} and interpreting names like {{mono|..}}.<ref name="w32paths" /> * [[Object Manager (Windows)|Windows NT object manager]] <code>\\??\</code>-prefixed paths (global DOS namespace).<ref>{{cite web |title=winapi - Is there a difference between \??\ and \\?\ paths? |website=Stack Overflow |url=https://stackoverflow.com/questions/25090101/is-there-a-difference-between-and-paths}}</ref><ref>{{cite web |title=Path prefixes \??\ and \\?\ |website=Stack Overflow |url=https://stackoverflow.com/a/46019856}}</ref> In versions of Windows prior to Windows XP, only the APIs that accept "long" device paths could accept more than 260 characters. The [[Windows shell|shell]] in [[Windows XP]] and [[Windows Vista]], [[explorer.exe]], allows path names up to 248 characters long.{{citation needed|date=February 2014}} Since UNCs start with two backslashes, and the backslash is also used for string escaping and in [[regular expression]]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 β <code>\\\\\\\\</code> β because the string and regular expression both require escaping. This can be simplified by using [[raw string]]s, as in C#'s <code>@"\\\\"</code> or Python's <code>r'\\\\'</code>, or regular expression literals, as in Perl's <code>qr{\\\\}</code>. ==POSIX pathname definition== Most Unix-like systems use a similar syntax.<ref>{{cite web |title=UNC Definition |website=ComputerLanguage.com |url=https://www.computerlanguage.com/results.php?definition=UNC}}</ref> [[POSIX]] allows treating a path beginning with two slashes in an implementation-defined manner,<ref>{{cite web |title=POSIX pathname resolution specification |url=https://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11}}</ref> though in other cases systems must treat multiple slashes as single slashes.<ref>{{cite web |title=POSIX pathname definition |url=http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_266}}</ref> Many applications on Unix-like systems (for example, [[secure copy|scp]], [[rcp (Unix)|rcp]], and [[rsync]]) use resource definitions such as: hostname:/directorypath/resource or [[list of URI schemes|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 {{code|/home/mark/}} and it contains subdirectory {{code|bobapples}}, relative paths to the subdirectory include {{code|./bobapples}} and {{code|bobapples}}, and the absolute path is {{code|/home/mark/bobapples}}. A command to change the working directory to the subdirectory: <syntaxhighlight lang="console> $ cd bobapples </syntaxhighlight> If the working directory was {{code|/home/jo}}, then the relative path {{code|../mark/bobapples}} specifies the subdirectory. The double dots {{code|..}} indicates a move up the directory hierarchy one level to {{code|/home}}, the rest indicates moving down to {{code|mark}} and then {{code|boapples}}. ===Microsoft shells=== {{More citations needed section|date=November 2020}} [[File:Dir command in Windows Command Prompt.png|thumb|300px|Screenshot of a [[Microsoft Windows|Windows]] [[Command Prompt]] shell showing filenames in a directory]] <!--Contrary to popular belief, --> 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 {{code|\\?\}}) does not support slashes.<ref name="w32paths" /> <code>A:\Temp\File.txt</code> is an absolute path that specifies a file named {{code|File.txt}} in the directory {{code|Temp}} which is in the root of drive {{code|A:}}: <code>C:..\File.txt</code> is a relative path that specifies file {{code|File.txt}} located in the parent of the working directory on drive {{code|C:}}: <code>Folder\SubFolder\File.txt</code> is a relative path that specifies file {{code|File.txt}} in directory {{code|SubFolder}} which is in directory {{code|Folder}} which is in the working directory of the current drive: <code>File.txt</code> is a relative path that specifies <code>File.txt</code> in the working directory: <code>\\.\COM1</code> specifies the first [[serial port]], [[COM (hardware interface)|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, {{code|dir /windows}} is invalid, but {{code|dir "/window"}} is valid. And {{code|cd}} is more lenient by allowing {{code|cd /windows}}. ==See also== * {{Annotated link|basename}} * {{Annotated link|Device file}} * {{Annotated link|dirname}} * {{Annotated link|Distributed file system}} * {{Annotated link|Filename}} * {{Annotated link|Filesystem Hierarchy Standard}} * {{Annotated link|Fully qualified file name}} * {{Annotated link|PATH (variable)}} * {{Annotated link|URL}} ==References== {{Reflist}} ==External links== * [https://www.linfo.org/path.html Path Definition] - The Linux Information Project (LINFO) * [https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file Naming Files, Paths, and Namespaces] - Local File Systems: Windows: [[Microsoft Docs]] {{Computer files}} [[Category:Computer file systems]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Anchor
(
edit
)
Template:Annotated link
(
edit
)
Template:Citation needed
(
edit
)
Template:Cite conference
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Computer files
(
edit
)
Template:For
(
edit
)
Template:Mono
(
edit
)
Template:More citations needed
(
edit
)
Template:More citations needed section
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Table alignment
(
edit
)
Template:Use dmy dates
(
edit
)