計算機路徑概念解析
From Wikipedia, the free encyclopedia
Text that identifies an item in a computer file system
For the environment variable, see 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 /, backslash \, or colon :.
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 component1 and Component1 can coexist at the same level in the hierarchy, whereas for a case-insensitive 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.[1][2][3]
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[edit] Multics first introduced a hierarchical file system with directories (separated by ">") in the mid-1960s.[4]
Around 1970, Unix introduced the slash / as its directory separator.
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., dir /w). In contrast, Unix uses the dash - as the switch prefix. The backslash \ 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.[5][6]
Summary of systems[edit]
The following table describes the syntax of paths in notable operating systems:
System Root dir. Path delim. Working dir. Parent dir. Home dir. Examples
Unix and Unix-like systems, including macOS[7] / / . .. ~ /home/user/docs/Letter.txt ./child ../../greatgrandparent ~/.rcinfo
Windows, Command Prompt \ (relative to current working directory root) or [drive letter]:\ or \\.\ or \\?\ or \\[Host name]\[Root name] (UNC) /[a] or \ . ..
C:\user\docs\Letter.txt /user/docs/Letter.txtC:\user\docs\somefile.ext:alternate stream name C:picture.jpg \\?\UNC\Server01\user\docs\Letter.txt \\.\COM1
PowerShell [drive letter]:/ or [drive name]:\ or [PSSnapIn name]\[PSProvider name]::[PSDrive root] or UNC /[a] or \ . .. ~ C:\user\docs\Letter.txt ~\DesktopUserDocs:/Letter.txt Variable:PSVersionTable Registry::HKEY_LOCAL_MACHINE\SOFTWARE\ Microsoft.PowerShell.Security\Certificate::CurrentUser\
UNC[8] \\[server]\[sharename]\ /
\\Server01\user\docs\Letter.txt
DOS, COMMAND.COM [drive letter]:\ or \\[server name]\[volume]\ \ . ..
C:\USER\DOCS\LETTER.TXT A:PICTURE.JPG \\SERVER01\USER\DOCS\LETTER.TXT
OS/2 [drive letter]:\ or \\[server name]\[volume]\ / or \ . ..
C:\user\docs\Letter.txt A:Picture.jpg \\SERVER01\USER\docs\Letter.txt
RSX-11 MCR[9] [device name]:
DR0:[30,12]LETTER.TXT;4[b]
TOPS-20 DCL[10] [device name]: .
PS:<USER.DOCS>LETTER.TXT,4
OpenVMS DCL[11][12] [device name]:[000000] or [NODE["accountname password"]]::[device name][000000]: . [] [-] SYS$LOGIN: NODE$DISK:[USER.DOCS]PHOTO.JPGUSER:[000000]000000.DIR[]IN_THIS_DIR.COM; [-.-]GreatGrandParent.TXT SYS$SYSDEVICE:[.DRAFTS]LETTER.TXT;4 GEIN::[000000]LETTER.TXT;4 SYS$LOGIN:LOGIN.COM
ProDOS AppleSoft BASIC[13] /[volume or drive name]/ /
/SCHOOL.DISK/APPLEWORKS/MY.REPORTFLIGHT.SIMULATOR,D2
AmigaOS Amiga CLI / AmigaShell[14] [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[15] [fs type[#option]:][:drive number or disc name.]$[c] . @ ^ & ADFS::MyDrive.$.Documents.Letter Net#MainServer::DataDrive.$.Main.sy10823 LanMan::WindowsC.$.Pictures.Japan/gif NFS:&.!Choices ADFS:%.IfThere @.inthisdir ^.^.greatgrandparent[d]
Symbian OS File manager \ \
\user\docs\Letter.txt
Domain/OS Shell[16] // (root of domain) or / (root of current node) / . \ ~ //node/home/user/docs/Letter.txt ./inthisdir \\greatgrandparent ~rcinfo
MenuetOS CMD / /
/file
Stratus VOS CLI %[system_name]#[module_name]> >
<
%sysname#module1>SubDir>AnotherDir
NonStop Kernel TACL[e]
.
\NODE.$DISK.SUBVOL.FILE \NODE.$DEVICE \NODE.$DEVICE.#SUBDEV.QUALIFIER
CP/M CCP[17] [drive letter:] no subdirectories, only user areas 0–F A:LETTER.TXT
GS/OS :[volume name]: or.[device name]: or [prefix]:[f] : or /
@ :Apps:Platinum.Paint:Platinum.Paint *:System:Finder .APPLEDISK3.5B/file
OpenHarmony exec, Oniro, including HarmonyOS[18][19] hb set -root [ROOT_PATH] or hb set -p --product [PRODUCT_NAME] > or / ./ ../
LOCAL/MEDIA_TYPE_/Download/Letter.txt
In programming languages[edit]
Most programming languages use the path representation of the underlying system, but some may also be system-independent.[2]
For instance, this C code is system-dependent and may fail on opposing systems:[1]
<span id="mwAsY"></span><span class="n" id="mwAsc">uxFile</span><span class="w" id="mwAsg"> </span><span class="o" id="mwAsk">=</span><span class="w" id="mwAso"> </span><span class="n" id="mwAss">fopen</span><span class="p" id="mwAsw">(</span><span class="s" id="mwAs0">"project/readme.txt"</span><span class="p" id="mwAs4">,</span><span class="w" id="mwAs8"> </span><span class="s" id="mwAtA">"r"</span><span class="p" id="mwAtE">)</span><span class="w" id="mwAtI"> </span><span class="c1" id="mwAtM">// Fails on Windows</span> <span class="n" id="mwAtQ">winFile</span><span class="w" id="mwAtU"> </span><span class="o" id="mwAtY">=</span><span class="w" id="mwAtc"> </span><span class="n" id="mwAtg">fopen</span><span class="p" id="mwAtk">(</span><span class="s" id="mwAto">"C:</span><span class="se" id="mwAts">\\</span><span class="s" id="mwAtw">Program Files</span><span class="se" id="mwAt0">\\</span><span class="s" id="mwAt4">bin</span><span class="se" id="mwAt8">\\</span><span class="s" id="mwAuA">config.bat"</span><span class="p" id="mwAuE">,</span><span class="w" id="mwAuI"> </span><span class="s" id="mwAuM">"r"</span><span class="p" id="mwAuQ">)</span><span class="w" id="mwAuU"> </span><span class="c1" id="mwAuY">// Fails on Unix</span>
In Java, the File.separator field stores the system-dependent separator.[20] Some functions preclude the need for the separator entirely. <span id="mwAvM"></span><span class="kn" id="mwAvQ">import</span><span class="w" id="mwAvU"> </span><span class="nn" id="mwAvY">java.io.File</span><span class="p" id="mwAvc">;</span> <span class="kn" id="mwAvg">import</span><span class="w" id="mwAvk"> </span><span class="nn" id="mwAvo">java.nio.file.Path</span><span class="p" id="mwAvs">;</span> <span class="kn" id="mwAvw">import</span><span class="w" id="mwAv0"> </span><span class="nn" id="mwAv4">java.nio.file.Paths</span><span class="p" id="mwAv8">;</span> <span class="c1" id="mwAwA">// ...</span> <span class="n" id="mwAwE">File</span><span class="w" id="mwAwI"> </span><span class="n" id="mwAwM">file</span><span class="w" id="mwAwQ"> </span><span class="o" id="mwAwU">=</span><span class="w" id="mwAwY"> </span><span class="k" id="mwAwc">new</span><span class="w" id="mwAwg"> </span><span class="n" id="mwAwk">File</span><span class="p" id="mwAwo">(</span><span class="s" id="mwAws">"path"</span><span class="w" id="mwAww"> </span><span class="o" id="mwAw0">+</span><span class="w" id="mwAw4"> </span><s