{{Short description|Text that identifies an item in a computer file system}} {{Use dmy dates|date=March 2020}} {{For|the environment variable|PATH (variable)}}
A '''path''' (or '''filepath''', '''file path''', '''pathname''', or similar) is a string that uniquely identifies an item in a hierarchical file system. Generally, a path is composed of directory names, special format specifiers, and optionally a filename, all separated by delimiters. This delimiter can vary by operating system, but popular, modern systems use the slash {{code|/}}, backslash {{code|\}}, or colon {{code|:}}.
The case-sensitivity of individual path components will vary based on operating system, or based on options specified at the time of a file system's creation or first use. In practice, this means that for a '''case-sensitive''' system, path components named {{code|component1}} and {{code|Component1}} can coexist at the same level in the hierarchy, whereas for a '''case-''in''sensitive''' file system, they cannot (an error will occur). macOS and Windows' native file systems are case-insensitive by default, whereas typical Linux file systems are case-sensitive.<ref name=":0">{{Cite web |title=File system formats available in Disk Utility on Mac |url=https://support.apple.com/guide/disk-utility/file-system-formats-dsku19ed921c/mac |access-date=2025-09-12 |website=Apple Support |language=en}} Includes a description of APFS, the default file system for macOS</ref><ref name=":1">{{Cite web |last=Matt Wojciakowski |title=Case Sensitivity |url=https://learn.microsoft.com/en-us/windows/wsl/case-sensitivity |access-date=2025-09-12 |website=learn.microsoft.com |language=en-us}} <q>Windows file system treats file and directory names as case-insensitive. FOO.txt and foo.txt will be treated as equivalent files. Linux file system treats file and directory names as case-sensitive. FOO.txt and foo.txt will be treated as distinct files.</q></ref><ref name=":2">{{Cite web |last=Day |first=Brittany |title=Understanding the Linux Filesystem Case Sensitivity Debate |url=https://linuxsecurity.com/features/linux-filesystem-case-sensitivity-debate |access-date=2025-09-12 |website=Linux Security |language=en-gb}} <q>Case sensitivity in Linux refers to files and directories recognizing differences between lowercase and uppercase characters in filenames. For instance, "File.txt" and "file.txt" would both be treated as two distinct files. This concept is integral to Unix-like operating systems, including Linux.</q></ref>
{{anchor |relative}}{{anchor |absolute}}A path can be either '''relative''' or '''absolute'''. A relative path is a path in relation to another, most often the working directory. An absolute path indicates a location regardless of the current directory; that is, it specifies all path components starting from the file system's root, and does not depend on context like a relative path does.
Paths are also essential for locating hierarchically-organized network resources, as seen in URLs and UNC paths.
== 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. |date=1965 |title=A general-purpose file system for secondary storage |volume=Part I |pages=213–229 |doi=10.1145/1463891.1463915 |doi-access=free |book-title=Proceedings of the November 30--December 1, 1965, fall joint computer conference, Part I on XX - AFIPS '65 (Fall, part I) |s2cid=16236414}}</ref>
Around 1970, Unix introduced the slash {{code|/}} as its directory separator.<ref name=":0" />
Originally, MS-DOS did not support directories. When adding the feature, using the Unix standard of a slash was not a good option since many existing commands used a slash as the switch prefix (i.e., {{code|dir /w}}). In contrast, Unix uses the dash {{code|-}} as the switch prefix. The backslash {{code|\}} was ultimately chosen instead for its similarity to the slash and not conflicting with existing commands. This convention continued into Windows. However, some areas of Windows do accept or understand Unix-style slashes also, such as PowerShell.<ref>{{cite web |date=10 February 2014 |title=Why Windows Uses Backslashes and Everything else Uses Forward Slashes |url=https://www.howtogeek.com/181774/why-windows-uses-backslashes-and-everything-else-uses-forward-slashes/}}</ref><ref>{{cite web |date=24 June 2005 |title=Why is the DOS path character "\"? |url=https://learn.microsoft.com/archive/blogs/larryosterman/why-is-the-dos-path-character}}</ref>
== Summary of systems == <!-- 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:{{Table alignment}} {| class="wikitable mw-collapsible mw-collapsed col3center col4center col5center col6center" style="font-size: 90%;" |- ! System ! Root dir. ! Path delim. ! Working dir. ! Parent dir. ! Home dir. ! Examples |- ! Unix and Unix-like systems, including macOS<ref>{{Cite web |date=2018-04-09 |title=File System Basics |url=https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html |access-date=2025-09-07 |website=developer.apple.com}}</ref> | {{mono|/}} | {{mono|/}} | {{mono|.}} | {{mono|..}} | {{mono|~}} | {{mono|/home/user/docs/Letter.txt}}<br>{{mono|./child}}<br>{{mono|../../greatgrandparent}}<br>{{mono|~/.rcinfo}} |- ! Windows, Command Prompt | {{mono|\}} (relative to current working directory root)<br>or {{mono|[drive letter]:\}}<br>or {{Mono|\\.\}}<br>or {{Mono|\\?\}}<br>or UNC | {{mono|/}}{{efn|name="windows-fslash"|Limited compatibility, may not work in all Windows programs}}<br>or {{mono|\}} | {{mono|.}} | {{mono|..}} | | {{mono|C:\user\docs\Letter.txt}}<br>{{mono|/user/docs/Letter.txt}}{{mono|C:\user\docs\somefile.ext:alternate stream name}} {{Mono|C:picture.jpg}}<br>{{mono|\\?\UNC\Server01\user\docs\Letter.txt}}<br>{{Mono|\\.\COM1}} |- ! PowerShell | {{mono|[drive letter]:/}}<br>or {{mono|[drive name]:\}}<br>or {{mono|[PSSnapIn name]\[PSProvider name]::[PSDrive root]}}<br>or UNC | {{mono|/}}{{efn|name="windows-fslash"}}<br>or {{mono|\}} | {{mono|.}} | {{mono|..}} | {{mono|~}} | {{mono|C:\user\docs\Letter.txt}}<br>{{mono|~\Desktop}}{{mono|UserDocs:/Letter.txt}}<br>{{mono|Variable:PSVersionTable}}<br>{{mono|Registry::HKEY_LOCAL_MACHINE\SOFTWARE\}}<br>{{mono|Microsoft.PowerShell.Security\Certificate::CurrentUser\}} |- !UNC<ref>{{Cite web |title=UNC Network Share Access (Windows) |url=https://www.ibm.com/docs/en/iodg/11.3.0?topic=credentials-unc-network-share-access-windows |access-date=2025-09-07 |website=www.ibm.com |language=en-us}}</ref> |{{mono|\\[server]\[sharename]\}} |{{Mono|/}} | | | |{{mono|\\Server01\user\docs\Letter.txt}} |- ! DOS, COMMAND.COM | {{mono|[drive letter]:\}}<br>or {{mono|\\[server name]\[volume]\}} | {{mono|\}} | {{mono|.}} | {{mono|..}} | | {{mono|C:\USER\DOCS\LETTER.TXT}}<br>{{mono|A:PICTURE.JPG}}<br>{{mono|\\SERVER01\USER\DOCS\LETTER.TXT}} |- ! OS/2 | {{mono|[drive letter]:\}}<br>or {{mono|\\[server name]\[volume]\}} | {{mono|/}}<br>or {{mono|\}} | {{mono|.}} | {{mono|..}} | | {{mono|C:\user\docs\Letter.txt}}<br>{{mono|A:Picture.jpg}}<br>{{mono|\\SERVER01\USER\docs\Letter.txt}} |- ! RSX-11 MCR<ref>{{Cite book |title=RSX-11M-PLUS MCR Operations Manual, RSX-11M-PLUS Version 4.0 |date=August 1987 |publisher=Digital Equipment Corporation |url=https://bitsavers.org/pdf/dec/pdp11/rsx11m_plus/RSX11Mplus_V4.x/2a/AA-JS12A-TC_RSX-11M-PLUS_4.0_MCR_Operations_Manual_Aug87.pdf#page=26 |at=2.2 File Specifications |id=AA-JS12A-TC}}</ref> | {{mono|[device name]:}} | | | | | {{mono|DR0:[30,12]LETTER.TXT;4}}{{efn|In order, the fields are {{code|ddnn:[g,m]:filename.type;version}}}} |- ! TOPS-20 DCL<ref>{{Cite tech report |url=https://apps.dtic.mil/sti/html/tr/ADA163675/index.html |title=Defense Data Network/TOPS-20 Tutorial. An Interactive Computer Program. |last=Herkert |first=Mark Klause Herman |last2=Smith |first2=Sheri Lynn |date=December 1985 |format=PDF}}</ref> | {{mono|[device name]:}} | {{mono|.}} | | | | {{mono|PS:<USER.DOCS>LETTER.TXT,4}} |- ! OpenVMS DCL<ref>{{Cite web |last=Rabe |first=Bernhard |date=2011-06-06 |title=OpenVMS & DCL on Alpha & VAX |url=https://osm.hpi.de/serveros/2011/OpenVMS/uebung/OpenVMS-DCL.pdf}}</ref><ref>{{Cite web |date=2025 |title=VSI OpenVMS User's Manual |url=https://docs.vmssoftware.com/docs/vsi-openvms-user-s-manual.pdf |access-date=2025-09-07 |website=VMS Software}}</ref> | {{mono|[device name]:[000000]}}<br>or {{mono|<nowiki>[NODE["accountname password"]]::[device name][000000]:</nowiki>}} | {{mono|.}} | {{mono|[]}} | {{mono|[-]}} | <small>{{mono|SYS$LOGIN:}}</small> | {{mono|NODE$DISK:[USER.DOCS]PHOTO.JPG}}{{Mono|USER:[000000]000000.DIR}}{{mono|[]IN_THIS_DIR.COM;}}<br>{{mono|[-.-]GreatGrandParent.TXT}}<br>{{mono|SYS$SYSDEVICE:[.DRAFTS]LETTER.TXT;4}}<br>{{mono|GEIN::[000000]LETTER.TXT;4}}<br>{{mono|SYS$LOGIN:LOGIN.COM}} |- ! ProDOS AppleSoft BASIC<ref>{{Cite book |title=ProDOS User's Manual |publisher=Apple Computer |year=1983 |pages=56–62}}</ref> | {{mono|/[volume or drive name]/}} | {{mono|/}} | | | | {{mono|/SCHOOL.DISK/APPLEWORKS/MY.REPORT}}{{mono|FLIGHT.SIMULATOR,D2}} |- ! AmigaOS Amiga CLI / AmigaShell<ref>{{Cite book |title=The AmigaDOS Manual |date=February 1986 |publisher=Bantam Computer Books |others=Produced by Commodore-Amiga, Inc. |isbn=978-0-553-34294-9 |pages=6–16}}</ref> | {{mono|[drive, volume, device, or assign name]:}} | {{mono|/}} | ''empty string'' | {{mono|/}} | | {{mono|Workbench:Utilities/MultiView}}<br>{{mono|DF0:S/Startup-Sequence}}<br>{{mono|S:Startup-Sequence}}<br>{{mono|TCP:en.wikipedia.com/80}} |- ! RISC OS ShellCLI<ref>{{Cite web |date=2015-11-03 |title=RISC OS PRMs: Volume 2: Chapter 44: Writing a filing system |url=http://www.riscos.com/support/developers/prm/writefs.html |access-date=2025-09-07 |website=www.riscos.com Technical Support: Programmer's Reference Manual |publisher=3QD Developments Ltd.}}</ref> | {{mono|[fs type[#option]:][:drive number or disc name.]$}}{{efn|{{code|&}}, {{code|%}}, and {{code|@}} can also be used to reference the root of the current user, the library, and the current directory respectively}} | {{mono|.}} | {{mono|@}} | {{mono|^}} | {{mono|&}} | {{mono|ADFS::MyDrive.$.Documents.Letter}}<br>{{mono|Net#MainServer::DataDrive.$.Main.sy10823}}<br>{{mono|LanMan::WindowsC.$.Pictures.Japan/gif}}<br>{{mono|NFS:&.!Choices}}<br>{{mono|ADFS:%.IfThere}}<br>{{mono|@.inthisdir}}<br>{{mono|^.^.greatgrandparent}}{{efn|When filesystems with filename extensions are mounted, {{code|.}} characters are changed to {{code|/}}, as in the {{mono|Japan/gif}} example above}} |- ! Symbian OS File manager | {{mono|\}} | {{mono|\}} | | | | {{mono|\user\docs\Letter.txt}} |- ! Domain/OS Shell<ref>{{Cite book |title=Getting Started with Domain/OS |date=May 1988 |publisher=Apollo Computer |pages=7{{hyp}}1–7{{hyp}}7 |url=https://bitsavers.org/pdf/apollo/SR10/002348-A00_Getting_Started_With_Domain_OS_May88.pdf#page=76}}</ref> | {{mono|//}} (root of domain)<br>or {{mono|/}} (root of current node) | {{mono|/}} | {{mono|.}} | {{mono|\}} | {{mono|~}} | {{mono|//node/home/user/docs/Letter.txt}}<br>{{mono|./inthisdir}}<br>{{mono|\\greatgrandparent}}<br>{{mono|~rcinfo}} |- ! MenuetOS CMD | {{mono|/}} | {{mono|/}} | | | |{{Mono|/file}} |- ! Stratus VOS CLI | {{mono|%[system_name]#[module_name]>}} | {{mono|>}} | | {{mono|<}} | |{{mono|%sysname#module1>SubDir>AnotherDir}} |- ! NonStop<br>Kernel TACL{{efn|Short for ''Tandem Advanced Command Language''}} | | {{mono|.}} | | | | {{mono|\NODE.$DISK.SUBVOL.FILE}}<br>{{mono|\NODE.$DEVICE}}<br>{{mono|\NODE.$DEVICE.#SUBDEV.QUALIFIER}} |- ! CP/M CCP<ref>{{Cite book |title=CP/M Operating System Manual |date=September 1983 |publisher=Digital Research |edition=3rd}}</ref> | {{mono|[drive letter:]}} | colspan="4" |''no subdirectories, only user areas 0–F'' |{{mono|A:LETTER.TXT}} |- ! GS/OS | {{mono|:[volume name]:}}<br>or{{mono|.[device name]:}}<br>or {{mono|[prefix]:}}{{efn|{{code|[prefix]}} may be a number (0–31), {{code|*}} (boot volume) or {{code|@}} (AppleShare home directory)}} | {{mono|:}}<br>or {{mono|/}} | | | {{mono|@}} | {{mono|:Apps:Platinum.Paint:Platinum.Paint}}<br>{{mono|*:System:Finder}}<br>{{mono|.APPLEDISK3.5B/file}} |- !OpenHarmony exec, Oniro, including HarmonyOS<ref>{{cite web |title=Introduction to the Shell |url=https://github.com/eDorUS/OpenHarmony_docs/blob/master/en/device-dev/kernel/kernel-small-debug-shell-overview.md |access-date=13 March 2024 |website=GitHub |publisher=OpenAtom OpenHarmony}}</ref><ref>{{cite web |title=exec |url=https://github.com/dashingcalico/OpenHarmony/blob/master/docs-en/kernel/exec.md |access-date=14 March 2024 |website=GitHub |publisher=OpenAtom OpenHarmony}}</ref> |{{mono|hb set -root [ROOT_PATH]}}<br>or {{mono|hb set -p --product [PRODUCT_NAME]}} |{{mono|> or /}} |{{mono|./}} |{{mono|../}} | |{{mono|LOCAL/MEDIA_TYPE_/Download/Letter.txt}} |}
== In programming languages ==
Most programming languages use the path representation of the underlying system, but some may also be system-independent.<ref name=":1" />
For instance, this C code is system-''dependent'' and may fail on opposing systems:<ref name=":0" />
<syntaxhighlight lang="c">uxFile = fopen("project/readme.txt", "r") // Fails on Windows winFile = fopen("C:\\Program Files\\bin\\config.bat", "r") // Fails on Unix </syntaxhighlight>
* In Java, the {{var|File.separator}} field stores the system-dependent separator.<ref>{{Cite web |title=Java Development Kit Version 17 API Specification |url=https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/File.html#separator |access-date=2025-09-07 |website=docs.oracle.com |language=en}}</ref> Some functions preclude the need for the separator entirely. :<syntaxhighlight lang="java">import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; // ... File file = new File("path" + File.separator + "file.txt"); Path path = Paths.get("path", "file.txt"); </syntaxhighlight> * In Python, the {{code|pathlib}} module offers system-independent path operations.<ref>{{Cite web |title=os.path — Common pathname manipulations |url=https://docs.python.org/3/library/os.path.html |access-date=2025-09-07 |website=Python documentation |language=en}}</ref> :<syntaxhighlight lang="python">from pathlib import Path
with (Path("path") / "to" / "file.txt").open() as open_file: ... </syntaxhighlight>
== In Unix == Most Unix-like systems use a similar syntax.<ref>{{cite web |title=UNC Definition |url=https://www.computerlanguage.com/results.php?definition=UNC |website=ComputerLanguage.com}}</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 consecutive slashes as one.<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, scp, rcp, and rsync) use resource definitions such as {{code|hostname:/directorypath/resource}}, or URI schemes with the service name (here 'smb'), like {{code|smb://hostname/directorypath/resource}}.<ref name=":2" />
=== In macOS === When macOS was being developed, it inherited some pathname choices from Classic Mac OS and the Unix-like NeXTSTEP. The classic Mac OS uses a {{Code|:}} while Unix and Unix-like systems use a {{Code|/}} as the path delimiter. As a solution, to preserve compatibility for software and familiarity for users, and to allow disk file systems to be used both by the classic Mac OS and macOS, some portions of macOS convert between colons and slashes in pathnames;<ref>{{Cite web |last=Chan |first=Alex |date=2021-12-01 |title=A tale of two path separators |url=https://alexwlchan.net/2021/slashes/ |access-date=2025-09-07 |website=alexwlchan.net |language=en}}</ref> for example, the HFS+ file system, from the classic Mac OS, converts colons in file names to slashes and, when reading a directory, converts slashes in filenames to colons,<ref name="sanchez-usenix">{{cite web |url=https://www.wsanchez.net/papers/USENIX_2000/ |title=The Challenges of Integrating the Unix and Mac OS Environments |first=Wilfredo |last=Sanches |date=2000}}</ref> and the Carbon toolkit converts colons in pathnames to slashes and slashes in path names to colons, and converts them back when providing filenames and pathnames to the caller.<ref name="sanchez-usenix" />
== In DOS and Windows == [[File:Dir command in Windows Command Prompt.png|thumb|300px|Screenshot of a Windows Command Prompt shell showing filenames in a directory]]{{See also|8.3 filename}} DOS and Windows have no single root directory; a root exists for each storage drive, indicated with a drive letter or through UNC.
Directory and file name comparisons are case-insensitive: "test.TXT" would match "Test.txt".<ref name="netpaths" />
Windows understands the following kinds of paths: * Local paths, such as {{code|C:\File}}. * Universal naming convention (UNC). * DOS device paths, such as {{code|\\.\C:\File}} or {{code|\\?\UNC\Server\Volume\File}}. The first, {{Code|\\?\}} skips path normalization. The second, {{code|\\.\}} uses the raw device namespace.<ref name="netpaths">{{cite web |last=De George |first=Andy |date=2022-12-14 |title=File path formats on Windows systems |url=https://learn.microsoft.com/dotnet/standard/io/file-path-formats |access-date=2019-07-14 |website=Microsoft Docs |department=}}</ref><ref name="w32paths">{{cite web |last=Ashcraft |first=Alvin |date=2024-08-28 |title=Naming Files, Paths, and Namespaces |url=https://learn.microsoft.com/windows/win32/fileio/naming-a-file |website=Microsoft Docs}}</ref>
In the Windows API, file I/O functions automatically convert {{code|/}} into {{code|\}} (except when using the {{code|\\?\}} prefix). Paths using standard Windows APIs (dating back to DOS and Win9x), were limited to 260 characters, or less, as defined by the environment variable {{Var|MAX_PATH}}. For backwards compatibility with legacy applications this limitation was not removed until Windows 10, build 1607, when it could be expanded to 32,767. Windows NT always supported the 32,767 path length internally but only if using Unicode APIs or forcing UNC paths by the {{Code|\\?\}} prefix.<ref>{{Cite web |last=Ashcraft |first=Alvin |date=2024-07-16 |title=Maximum Path Length Limitation - Win32 apps |url=https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation |access-date=2025-09-07 |website=learn.microsoft.com |language=en-us}}</ref>
PowerShell allows slash-interoperability for backwards-compatibility:<ref>{{Cite web |last=Wheeler |first=Sean |title=about_Path_Syntax - PowerShell |url=https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_path_syntax?view=powershell-7.5 |access-date=2025-09-07 |website=learn.microsoft.com |language=en-us}}</ref>
<syntaxhighlight lang="powershell">PS C:\>Get-Content -Path "C:/path/to/file.txt"
Here is some text within a file</syntaxhighlight>
=== Yen/won character error === {{Main|Backslash#Confusion with ¥ and other characters}}
Japanese and Korean versions of Windows often displayed the '¥' character or the '₩' character instead of the directory separator. This is because while in ANSI codepages, the character at 0x5C was the backslash, and in Japanese and Korean codepages, 0x5C was the yen and won signs, respectively. Therefore, when the character for a backslash was used, other glyphs appeared.<ref>{{cite web |title=When is a backslash not a backslash? |url=http://archives.miloush.net/michkap/archive/2005/09/17/469941.html |website=Sorting it all Out}}</ref>
=== Universal Naming Convention === {{Anchor|UNC}}
The Microsoft '''Universal Naming Convention''' ('''UNC''', '''uniform naming convention''', or '''network path'''), is 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:<ref name=":1" />
{{Mono|\\ComputerName\SharedFolder\Resource}}
Some Windows interfaces 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. Thus, the WebDAV URL of {{code|https://hostname:443/SharedFolder/Resource}} becomes {{code|\\hostname@SSL@443\SharedFolder\Resource}}.<ref>{{cite web |date=13 October 2021 |title=DavGetHTTPFromUNCPath function |url=https://learn.microsoft.com/windows/win32/api/davclnt/nf-davclnt-davgethttpfromuncpath |access-date=2023-10-04 |website=Microsoft Docs |series=series |department=WebDAV: Windows}}</ref>
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 during creation of the share.
Since UNCs start with two backslashes, and the backslash is also used for escape sequences and in regular expressions, cases of leaning toothpick syndrome may arise. An escaped string for a regular expression matching a UNC begins with 8 backslashes {{code|\\\\\\\\}} because the string and regular expression both require escaping. This can be simplified by using raw strings, such as {{code|@"\\\\"|csharp}} in C#, {{code|r'\\\\'|python}} in Python, or {{code|qr{\\\\}|perl}} in Perl.
== 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}}
== Notes == {{Notelist}}
== References == {{Reflist}}
{{Computer files}}
Category:Computer file systems