大网数据广告活动
磁盘与文件系统

Creating Symbolic Links

· 52CE 我爱测

Create symbolic links that use either an absolute or relative path by using the CreateSymbolicLink function.

The function CreateSymbolicLink allows you to create symbolic links using either an absolute or relative path.

Symbolic links can either be absolute or relative links. Absolute links are links that specify each portion of the path name; relative links are determined relative to where relative–link specifiers are in a specified path. Relative links are specified using the following conventions:

  • Dot (. and ..) conventions—for example, "..\" resolves the path relative to the parent directory.

  • Names with no slashes (\)—for example, "tmp" resolves the path relative to the current directory.

  • Root relative—for example, "\Windows\System32" resolves to the "current drive:\Windows\System32". directory

  • Current working directory-relative—for example, if the current working directory is "C:\Windows\System32", "C:File.txt" resolves to "C:\Windows\System32\File.txt".

    [!NOTE] If you specify a current working directory–relative link, it is created as an absolute link, due to the way the current working directory is processed based on the user and the thread.

A symbolic link can also contain both junction points and mounted folders as a part of the path name.

Symbolic links can point directly to a remote file or directory using the UNC path.

Relative symbolic links are restricted to a single volume.

Example of an Absolute Symbolic Link

In this example, the original path, 'X' ,contains a component, 'absLink', which is an absolute symbolic link. When 'absLink' is encountered, the fragment of the original path up to and including 'absLink' is completely replaced by the path that is pointed to by 'absLink'. The remainder of the path after 'absLink' is appended to this new path. This now becomes the modified path.

X: "C:\alpha\beta\absLink\gamma\file"

Link: "absLink" maps to "\\machineB\share"

Modified Path: "\\machineB\share\gamma\file"

Example of a Relative Symbolic Links

In this example, the original path, 'x', contains a component 'link', which is a relative symbolic link. When 'link' is encountered, 'link' is completely replaced by the new fragment pointed to by 'link'. The remainder of the path after 'link', is appended to the new path. Any dots (..) in this new path replace components that appear before the dots (..). Each set of dots replace the component preceding. If the number of dots (..) exceed the number of components, an error is returned. Otherwise, when all component replacement has finished, the final, modified path remains.

X: C:\alpha\beta\link\gamma\file

Link: "link" maps to "..\..\theta"

Modified Path: "C:\alpha\beta\..\..\theta\gamma\file"

Final Path: "C:\theta\gamma\file"

Related topics

Symbolic Links

Hard Links and Junctions

Naming Files, Paths, and Namespaces

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 09/19/2024
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。