Sort method
sort_method
#
File Handling Utility.
This module provides functionality to handle files with different actions such as moving, copying, creating symbolic links, and creating hard links.
Classes:
Name | Description |
---|---|
FileAction |
Enum for file actions including MOVE, COPY, SYMLINK, and HARDLINK. |
Functions:
Name | Description |
---|---|
handle_file |
Perform specified file operations (move, copy, symlink, hardlink) on a file. |
Notes
Symlinks vs. Hardlinks:
- Symlinks (Symbolic Links):
A symbolic link is a shortcut or reference to another file. It creates a new
file that points to the target file but does not duplicate the file's data.
If the target file is moved or deleted, the symlink becomes invalid.
Example: ln -s target symlink
- Hardlinks:
A hard link is an additional reference to the same data on the disk. Both the
original file and the hard link share the same inode, meaning they are
indistinguishable. Deleting the original file does not affect the hard link,
and vice versa.
Example:
ln target hardlink
Examples:
Move a file: >>> from pathlib import ( ... Path, ... ) >>> handle_file( ... Path("source.txt"), ... Path("destination.txt"), ... action=FileAction.MOVE, ... )
Create a symlink: >>> handle_file( ... Path("source.txt"), ... Path("symlink.txt"), ... action=FileAction.SYMLINK, ... )
Copy a file: >>> handle_file( ... Path("source.txt"), ... Path("copy.txt"), ... action=FileAction.COPY, ... overwrite=True, ... )