You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8a189e0
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/standard/io/file-path-formats.md
+21-20Lines changed: 21 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@ helpviewer_keywords:
11
11
- "path formats, Windows"
12
12
ai-usage: ai-assisted
13
13
---
14
+
14
15
# File path formats on Windows systems
15
16
16
17
Members of many of the types in the <xref:System.IO> namespace include a `path` parameter that lets you specify an absolute or relative path to a file system resource. This path is then passed to [Windows file system APIs](/windows/desktop/fileio/file-systems). This topic discusses the formats for file paths that you can use on Windows systems.
@@ -25,8 +26,8 @@ A standard DOS path can consist of three components:
25
26
26
27
If all three components are present, the path is absolute. If no volume or drive letter is specified and the directory name begins with the [directory separator character](<xref:System.IO.Path.DirectorySeparatorChar>), the path is relative from the root of the current drive. Otherwise, the path is relative to the current directory. The following table shows some possible directory and file paths.
27
28
28
-
|Path |Description |
29
-
| -- | -- |
29
+
|Path | Description|
30
+
| ---|--- |
30
31
|`C:\Documents\Newsletters\Summer2018.pdf`| An absolute file path from the root of drive `C:`. |
31
32
|`\Program Files\Custom Utilities\StringFinder.exe`| A relative path from the root of the current drive. |
32
33
|`2018\January.xlsx`| A relative path to a file in a subdirectory of the current directory. |
@@ -55,24 +56,24 @@ Universal naming convention (UNC) paths, which are used to access network resour
55
56
56
57
The following are some examples of UNC paths:
57
58
58
-
|Path |Description |
59
-
| -- | -- |
59
+
|Path | Description|
60
+
| ---|--- |
60
61
|`\\system07\C$\`| The root directory of the `C:` drive on `system07`. |
61
-
|`\\Server2\Share\Test\Foo.txt`| The `Foo.txt` file in the Test directory of the `\\Server2\Share` volume.|
62
+
|`\\Server2\Share\Test\Foo.txt`| The `Foo.txt` file in the Test directory of the `\\Server2\Share` volume.|
62
63
63
64
UNC paths must always be fully qualified. They can include relative directory segments (`.` and `..`), but these must be part of a fully qualified path. You can use relative paths only by mapping a UNC path to a drive letter.
64
65
65
66
## DOS device paths
66
67
67
68
The Windows operating system has a unified object model that points to all resources, including files. These object paths are accessible from the console window and are exposed to the Win32 layer through a special folder of symbolic links that legacy DOS and UNC paths are mapped to. This special folder is accessed via the DOS device path syntax, which is one of:
68
69
69
-
`\\.\C:\Test\Foo.txt`
70
-
`\\?\C:\Test\Foo.txt`
70
+
-`\\.\C:\Test\Foo.txt`
71
+
-`\\?\C:\Test\Foo.txt`
71
72
72
73
In addition to identifying a drive by its drive letter, you can identify a volume by using its volume GUID. This takes the form:
> DOS device path syntax is supported on .NET implementations running on Windows starting with .NET Core 1.1 and .NET Framework 4.6.2.
@@ -81,19 +82,19 @@ The DOS device path consists of the following components:
81
82
82
83
- The device path specifier (`\\.\` or `\\?\`), which identifies the path as a DOS device path.
83
84
84
-
> [!NOTE]
85
-
> The `\\?\` is supported in all versions of .NET Core and .NET 5+ and in .NET Framework starting with version 4.6.2.
85
+
> [!NOTE]
86
+
> The `\\?\` is supported in all versions of .NET Core and .NET 5+ and in .NET Framework starting with version 4.6.2.
86
87
87
88
- A symbolic link to the "real" device object (C: in the case of a drive name, or Volume{b75e2c83-0000-0000-0000-602f00000000} in the case of a volume GUID).
88
89
89
-
The first segment of the DOS device path after the device path specifier identifies the volume or drive. (For example, `\\?\C:\` and `\\.\BootPartition\`.)
90
+
The first segment of the DOS device path after the device path specifier identifies the volume or drive. (For example, `\\?\C:\` and `\\.\BootPartition\`.)
90
91
91
-
There is a specific link for UNCs that is called, not surprisingly, `UNC`. For example:
92
+
There is a specific link for UNCs that is called, not surprisingly, `UNC`. For example:
92
93
93
-
`\\.\UNC\Server\Share\Test\Foo.txt`
94
-
`\\?\UNC\Server\Share\Test\Foo.txt`
94
+
-`\\.\UNC\Server\Share\Test\Foo.txt`
95
+
-`\\?\UNC\Server\Share\Test\Foo.txt`
95
96
96
-
For device UNCs, the server/share portion forms the volume. For example, in `\\?\server1\utilities\\filecomparer\`, the server/share portion is `server1\utilities`. This is significant when calling a method such as <xref:System.IO.Path.GetFullPath(System.String,System.String)?displayProperty=nameWithType> with relative directory segments; it is never possible to navigate past the volume.
97
+
For device UNCs, the server/share portion forms the volume. For example, in `\\?\server1\utilities\\filecomparer\`, the server/share portion is `server1\utilities`. This is significant when calling a method such as <xref:System.IO.Path.GetFullPath(System.String,System.String)?displayProperty=nameWithType> with relative directory segments; it is never possible to navigate past the volume.
97
98
98
99
DOS device paths are fully qualified by definition and can't begin with a relative directory segment (`.` or `..`). Current directories never enter into their usage.
99
100
@@ -164,7 +165,7 @@ As the path is processed, any components or segments that are composed of a sing
164
165
165
166
- For a double period, the current segment and the parent segment are removed, since the double period refers to the parent directory.
166
167
167
-
Parent directories are only removed if they aren't past the root of the path. The root of the path depends on the type of path. It is the drive (`C:\`) for DOS paths, the server/share for UNCs (`\\Server\Share`), and the device path prefix for device paths (`\\?\` or `\\.\`).
168
+
Parent directories are only removed if they aren't past the root of the path. The root of the path depends on the type of path. It is the drive (`C:\`) for DOS paths, the server/share for UNCs (`\\Server\Share`), and the device path prefix for device paths (`\\?\` or `\\.\`).
168
169
169
170
### Trim characters
170
171
@@ -174,10 +175,10 @@ Along with the runs of separators and relative segments removed earlier, some ad
174
175
175
176
- If the path doesn't end in a separator, all trailing periods and spaces (U+0020) are removed. If the last segment is simply a single or double period, it falls under the relative components rule above.
176
177
177
-
This rule means that you can create a directory name with a trailing space by adding a trailing separator after the space.
178
+
This rule means that you can create a directory name with a trailing space by adding a trailing separator after the space.
178
179
179
-
> [!IMPORTANT]
180
-
> You should **never** create a directory or filename with a trailing space. Trailing spaces can make it difficult or impossible to access a directory, and applications commonly fail when attempting to handle directories or files whose names include trailing spaces.
180
+
> [!IMPORTANT]
181
+
> You should **never** create a directory or filename with a trailing space. Trailing spaces can make it difficult or impossible to access a directory, and applications commonly fail when attempting to handle directories or files whose names include trailing spaces.
0 commit comments