os.symlink()

os.symlink(src, dst, target_is_directory=False, *, dir_fd=None)

Create a symbolic link pointing to src named dst.

On Windows, a symlink represents either a file or a directory, and does not morph to the target dynamically. If the target is present, the type of the symlink will be created to match. Otherwise, the symlink will be created as a directory if target_is_directory is True or a file symlink (the default) otherwise. On non-Window platforms, target_is_directory is ignored.

Symbolic link support was introduced in Windows 6.0 (Vista). symlink() will raise a NotImplementedError on Windows versions earlier than 6.0.

This function can support paths relative to directory descriptors.

Note

On Windows, the SeCreateSymbolicLinkPrivilege is required in order to successfully create symlinks. This privilege is not typically granted to regular users but is available to accounts which can escalate privileges to the administrator level. Either obtaining the privilege or running your application as an administrator are ways to successfully create symlinks.

OSError is raised when the function is called by an unprivileged user.

Availability: Unix, Windows.

Changed in version 3.2: Added support for Windows 6.0 (Vista) symbolic links.

New in version 3.3: Added the dir_fd argument, and now allow target_is_directory on non-Windows platforms.

doc_python
2016-10-07 17:40:03
Comments
Leave a Comment

Please login to continue.