This article needs additional citations for verification .(July 2008) |
A path (or filepath, file path, pathname, or similar) is a string of characters used to uniquely identify a location in a directory structure. It is composed by following the directory tree hierarchy in which components, separated by a delimiting character, represent each directory. The delimiting character is most commonly the slash ("/"), the backslash character ("\"), or colon (":"), though some operating systems may use a different delimiter. 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). Resources can be represented by either absolute or relative paths.
Multics first introduced a hierarchical file system with directories (separated by ">") in the mid-1960s. [1]
Around 1970, Unix introduced the slash character ("/") as its directory separator.
In 1981, the first version of Microsoft DOS was released. MS-DOS 1.0 did not support file directories. Also, a major portion of the utility commands packaged with MS-DOS 1.0 came from IBM and their command line syntax used the slash character as a 'switch' prefix. For example, dir /w
runs the dir
command with the wide list format option.
This use of slash can still be found in the command interface under Microsoft Windows. By contrast, Unix uses the hyphen-minus character ("-") as a command-line switch prefix.
When directory support was added to MS-DOS in version 2.0, "/" was kept as the switch prefix character for backward compatibility. Microsoft chose the backslash character ("\") as a directory separator, which looks similar to the slash character, though more modern version of Windows are slash-agnostic, allowing mixing of both types of slash in a path. [2] [3]
An absolute or full path points to the same location in a file system, regardless of the current working directory. To do that, it must include the root directory.
By contrast, a relative path starts from some given working directory, avoiding the need to provide the full absolute path. A filename can be considered as a relative path based at the current working directory. If the working directory is not the file's parent directory, a file not found error will result if the file is addressed by its name.
A base URL is the consistent part of an API path, to which endpoint paths are appended.
Operating system | Shell | Root directory | Directory separator | Current directory | Parent directory | Home directory | Examples |
---|---|---|---|---|---|---|---|
Unix-like OS (incl. macOS) | Unix shell | / | / | . | .. | ~ | /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 | |
Microsoft Windows | cmd.exe | \ (relative to current working directory root)or [drive_letter]:\ or \\[server]\[sharename]\ or \\?\[drive_spec]:\ or \\?\UNC\[server]\[sharename]\ or \\.\[physical_device]\ [4] | / or \ , The Japanese edition uses ¥, the Korean version uses ₩ as Path separator | . | .. [5] | 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
| / or \ | . | .. | ~ | C:\user\docs\Letter.txt C:\user/docs\Letter.txt \\Server01\user\docs\Letter.txt cd ~\Desktop
| |
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
| . | [] | [-] | SYS$LOGIN: | SYS$SYSDEVICE:[USER.DOCS]PHOTO.JPG
|
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
| |||
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 | . | @ | ^ | & | 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, |
Symbian OS | File manager | \ | \ | \user\docs\Letter.txt | |||
Domain/OS | Shell |
| / | . | \ | ~ | //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 | . | no parent directory | \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), | : or / | @ | :Apps:Platinum.Paint:Platinum.Paint *:System:Finder .APPLEDISK3.5B/file | |||
OpenHarmony (incl. HarmonyOS) | exec [6] [7] | hb set -root [ROOT_PATH]
| > | ./ | ../ | LOCAL>MEDIA_TYPE_>Download>Letter.txt |
Japanese and Korean versions of Windows may 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. [8]
Mac OS X, 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).
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).
The Microsoft Windows UNC, short for Universal Naming Convention or Uniform Naming Convention, specifies a common syntax to describe the location of a network resource, such as a shared file, directory, or printer. The UNC syntax for Windows systems has the generic form:
\\ComputerName\SharedFolder\Resource
Microsoft often refers to this as a "network path".
Some Microsoft Windows interfaces also allow or require UNC syntax for WebDAV share access, rather than a URL. The UNC syntax is extended [9] 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 Microsoft Windows interfaces also accept the "Long UNC":
\\?\UNC\ComputerName\SharedFolder\Resource
Microsoft Windows uses the following types of paths:
C:\File
\\Server\Volume\File
or /<internet resource name>[\Directory name]
(at least in Windows 7 and later)\\?\C:\File
or \\?\UNC\Server\Volume\File
. [10] 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 ... [4] \\??\
-prefixed paths (global DOS namespace). [11] [12] 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.[ 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{\\\\}
.
Most Unix-like systems use a similar syntax. [13] POSIX allows treating a path beginning with two slashes in an implementation-defined manner, [14] though in other cases systems must treat multiple slashes as single slashes. [15] 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
The following worked example discusses the behavior of a Unix-style file system as it would appear from a terminal or terminal application (command-line window):
Attached to a current working directory (cwd) of:
/users/mark/
One wants to change the current working directory to:
/users/mark/bobapples
At that moment, the relative path for the desired directory can be represented as:
./bobapples
or for short:
bobapples
and the absolute path for the directory as:
/users/mark/bobapples
Given bobapples as the relative path for the directory wanted, the following may be typed at the command prompt to change the current working directory to bobapples:
cd bobapples
Two dots ("..") point upward in the hierarchy, to indicate the parent directory; one dot (".") represents the current directory itself. Both can be components of a complex relative path (e.g., "../mark/./bobapples"), where "." alone or as the first component of such a relative path represents the working directory. (Using "./foo" to refer to a file "foo" in the current working directory can sometimes usefully distinguish it from a resource "foo" to be found in a default directory or by other means; for example, to view a specific version of a manual page instead of the one installed in the system.)
This section needs additional citations for verification .(November 2020) |
Contrary to popular belief, the Windows system API accepts slash, and thus all the above Unix examples should work. But many applications on Windows interpret a slash for other purposes or treat it as an invalid character, and thus require you to enter backslash – notably the cmd.exe shell (often called the "terminal" as it typically runs in a terminal window). Note that many other shells available for Windows, such as tcsh and Windows PowerShell, allow the slash.
In addition "\" does not indicate a single root, but instead the root of the "current disk". Indicating a file on a disk other than the current one requires prefixing a drive letter and colon. No ambiguity ensues, because colon is not a valid character in an MS-DOS filename, and thus one cannot have a file called "A:" in the current directory.
UNC names (any path starting with \\?\) do not support slashes. [4]
The following examples show MS-DOS/Windows-style paths, with backslashes used to match the most common syntax:
A:\Temp\File.txt
This path points to a file with the name File.txt, located in the directory Temp, which in turn is located in the root directory of the drive A:.
C:..\File.txt
This path refers to a file called File.txt located in the parent directory of the current directory on drive C:.
Folder\SubFolder\File.txt
This path denotes a file called File.txt located in SubFolder directory which in turn is located in Folder directory which is located in the current directory of the current drive (since this example gives no drive-specification).
File.txt
This rather simple path points to a file named File.txt
located in the current directory (since the path lacks a directory-specification) on the current drive (since no drive specification is present).
\\.\COM1
This path refers to the first serial port (COM1).
C:\>more < C:/Windows/system.ini ; for 16-bit app support[386Enh]woafont=dosapp.fonEGA80WOA.FON=EGA80WOA.FONEGA40WOA.FON=EGA40WOA.FONCGA80WOA.FON=CGA80WOA.FONCGA40WOA.FON=CGA40WOA.FON...
This example uses a path containing slashes as directory separator. The command redirects the content of the file to the more
command.
E:\>dir"/Folder/SubFolder/" /Q Volume in drive E is Data Volume Serial Number is 07BE-0B10 Directory of E:\Folder\SubFolder18 October 2008 08:15 AM <DIR> DOMAIN\user . 18 October 2008 08:15 AM <DIR> DOMAIN\user .. 18 October 2008 08:15 AM <DIR> DOMAIN\user File.txt 1 File(s) 8 bytes 2 Dir(s) 19,063,000 bytes free
A path containing forward slashes often needs to be surrounded by double quotes to disambiguate it from command-line switches.
CD "[drive letter]:/Program Files" will only work from the root ([drive letter]:\) directory. This appears to treat all forward slashes the same as .\. [ citation needed ]
For example:
CD "C:.\Program Files"
works the same as
CD "C:/Program Files"
Also, from a root folder:
CD "C:.\Program Files.\Internet Explorer"
would be treated the same as
CD "C:/Program Files/Internet Explorer"
If there is no relative path to the directory name specified with forward slashes you will get the following error:
The system cannot find the path specified.
For setting environment variables, it is sometimes necessary to provide a path that does not contain spaces in it, for instance %JAVA_HOME%
defined as "C:\Program Files\Java..." can cause scripts to halt when they encounter the space in the path name. To get the eight-character name Windows assigns to any directory for substitution in environment variables, use the directory listing command with the /x option one level up from the target directory. For instance, the following will display the 8.3 filenames for all directories directly under root:
C:\>dir /x
(Users can disable 8.3 filename creation on a drive-by-drive basis.)
In computing, a computer file is a resource for recording data on a computer storage device, primarily identified by its filename. Just as words can be written on paper, so too can data be written to a computer file. Files can be shared with and transferred between computers and mobile devices via removable media, networks, or the Internet.
An 8.3 filename is one that obeys the filename convention used by CP/M and old versions of DOS and versions of Microsoft Windows prior to Windows 95 and Windows NT 3.5. It is also used in modern Microsoft operating systems as an alternate filename to the long filename, to provide compatibility with legacy programs. The filename convention is limited by the FAT file system. Similar 8.3 file naming schemes have also existed on earlier CP/M, TRS-80, Atari, and some Data General and Digital Equipment Corporation minicomputer operating systems.
The cd
command, also known as chdir
, is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.
In computing, dir
(directory) is a command in various computer operating systems used for computer file and directory listing. It is one of the basic commands to help navigate the file system. The command is usually implemented as an internal command in the command-line interpreter (shell). On some systems, a more graphical representation of the directory structure can be displayed using the tree
command.
The backslash\ is a mark used mainly in computing and mathematics. It is the mirror image of the common slash /. It is a relatively recent mark, first documented in the 1930s. It is sometimes called a hack, whack, escape, reverse slash, slosh, downwhack, backslant, backwhack, bash, reverse slant, reverse solidus, and reversed virgule.
An environment variable is a user-definable value that can affect the way running processes will behave on a computer. Environment variables are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.
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.
In computer programming, glob patterns specify sets of filenames with wildcard characters. For example, the Unix Bash shell command mv *.txttextfiles/
moves all files with names ending in .txt
from the current directory to the directory textfiles
. Here, *
is a wildcard and *.txt
is a glob pattern. The wildcard *
stands for "any string of any length including empty, but excluding the path separator characters ".
In Unix-like operating systems, find
is a command-line utility that locates files based on some user-specified criteria and either prints the pathname of each matched object or, if another action is requested, performs that action on each matched object.
In computing, more
is a command to view the contents of a text file one screen at a time. It is available on Unix and Unix-like systems, DOS, Digital Research FlexOS, IBM/Toshiba 4690 OS, IBM OS/2, Microsoft Windows and ReactOS. Programs of this sort are called pagers. more
is a very basic pager, originally allowing only forward navigation through a file, though newer implementations do allow for limited backward movement.
Long filename (LFN) support is Microsoft's backward-compatible extension of the 8.3 filename naming scheme used in MS-DOS. Long filenames can be more descriptive, including longer filename extensions such as .jpeg
, .tiff
, and .html
that are common on other operating systems, rather than specialized shortened names such as .jpg
, .tif
, or .htm
. The standard has been common with File Allocation Table (FAT) filesystems since its first implementation in Windows NT 3.5 of 1994.
In computing, a hidden folder or hidden file is a folder or file which filesystem utilities do not display by default when showing a directory listing. They are commonly used for storing user preferences or preserving the state of a utility and are frequently created implicitly by using various utilities. They are not a security mechanism because access is not restricted – usually the intent is simply to not "clutter" the display of the contents of a directory listing with files the user did not directly create.
NTFS links are the abstraction used in the NTFS file system—the default file system for all Microsoft Windows versions belonging to the Windows NT family—to associate pathnames and certain kinds of metadata, with entries in the NTFS Master File Table (MFT). NTFS broadly adopts a pattern akin to typical Unix file systems in the way it stores and references file data and metadata; the most significant difference is that in NTFS, the MFT "takes the place of" inodes, fulfilling most of the functions which inodes fulfill in a typical Unix filesystem.
In programming, a file uniform resource identifier (URI) scheme is a specific format of URI, used to specifically identify a file on a host computer. While URIs can be used to identify anything, there is specific syntax associated with identifying files.
A batch file is a script file in DOS, OS/2 and Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. A batch file may contain any command the interpreter accepts interactively and use constructs that enable conditional branching and looping within the batch file, such as IF
, FOR
, and GOTO
labels. The term "batch" is from batch processing, meaning "non-interactive execution", though a batch file might not process a batch of multiple data.
In computing, pushd
and popd
are a pair of commands which allow users to quickly switch between the current and previous directory when using the command line. When called, they use a directory stack to sequentially save and retrieve directories visited by the user.
PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting.
In computing, a directory structure is the way an operating system arranges files that are accessible to the user. Files are typically displayed in a hierarchical tree structure.
A command-line interface (CLI) is a means of interacting with a computer program by inputting lines of text called command-lines. Command-line interfaces emerged in the mid-1960s, on computer terminals, as an interactive and more user-friendly alternative to the non-interactive interface available with punched cards.
In computing, findstr is a command in the command-line interpreters (shells) of Microsoft Windows and ReactOS. It is used to search for a specific text string in computer files.