Skip to content

Links — link_*

link_create(path, new_path) creates new_path pointing to path (the fs argument order). Symbolic links are the default.

link_create(path: str, new_path: PathInput, *, symbolic: bool = True) -> FsPath

Create a link at new_path pointing to path.

Note the argument order (fs's): target first, link name second.

Parameters:

Name Type Description Default
path str or PathLike

What the link points to (need not exist for symbolic links).

required
new_path str or PathLike

Where to create the link.

required
symbolic bool

Symbolic link (default) or hard link.

True

Returns:

Type Description
FsPath

The new link's path.

Raises:

Type Description
FileExistsError

If new_path already exists.

See Also

link_path : Read where a symlink points.

Examples:

>>> from pyrfs import file_touch
>>> _ = file_touch("big.csv")
>>> link_create("big.csv", "latest.csv")
FsPath('latest.csv')
>>> link_path("latest.csv")
FsPath('big.csv')
link_path(path: str) -> FsPath

Return the target a symlink points to (OSError if not a symlink).

Vectorized: also accepts an iterable or pandas Series of paths.

See Also

pyrfs.path_real : Fully resolve a path through all links.

link_exists(path: str) -> bool

Whether the path is a symlink (its target need not exist).

Equivalent to pyrfs.is_link. Vectorized: also accepts an iterable or pandas Series of paths.

link_copy(path: str, new_path: PathInput, *, overwrite: bool = False) -> FsPath

Copy a symlink itself (the new link points to the same target).

The target is not copied — use pyrfs.file_copy to copy what the link points to.

Parameters:

Name Type Description Default
path str or PathLike

An existing symlink.

required
new_path str or PathLike

Where to create the duplicate link.

required
overwrite bool

Allow clobbering an existing destination (default False).

False

Raises:

Type Description
FileExistsError

If the destination exists and overwrite is False.

link_delete(path: str) -> FsPath

Delete a symlink — the target is untouched; non-links are refused.

Raises:

Type Description
FsValueError

If path is not a symlink (use pyrfs.file_delete or pyrfs.dir_delete for real files).

Examples:

>>> from pyrfs import file_exists, file_touch
>>> _ = file_touch("real.txt")
>>> _ = link_create("real.txt", "ln.txt")
>>> _ = link_delete("ln.txt")
>>> file_exists("real.txt")  # target survives
True