absfuyu.util.path module
Absfuyu: Path
Path related
Version: 5.1.0 Date updated: 10/03/2025 (dd/mm/yyyy)
Feature:
Directory
SaveFileAs
- absfuyu.util.path.DirectoryBase
alias of
AutoSubclass
- class absfuyu.util.path.Directory(source_path: str | Path, create_if_not_exist: bool = False)[source]
Bases:
DirectoryTreeMixin
,DirectoryOrganizerMixin
,DirectoryArchiverMixin
,DirectoryBasicOperationMixin
,DirectoryInfoMixin
Some shortcuts for directory
- Parameters:
source_path (str | Path) – Source folder
create_if_not_exist (bool) – Create directory when not exist, by default
False
Example:
>>> # For a list of method >>> Directory.SUBCLASS_METHODS
- class absfuyu.util.path.SaveFileAs(data: Any, *, encoding: str | None = 'utf-8')[source]
Bases:
object
File as multiple file type
- class absfuyu.util.path.DirectoryInfoMixin(source_path: str | Path, create_if_not_exist: bool = False)[source]
Bases:
AutoSubclass
Directory - Info
Quick info
- quick_info() DirectoryInfo [source]
Quick information about this Directory
- Returns:
DirectoryInfo
- Return type:
Added in version 3.3.0
Deprecated in version 5.1.0: Not efficient
- class absfuyu.util.path.DirectoryBasicOperationMixin(source_path: str | Path, create_if_not_exist: bool = False)[source]
Bases:
AutoSubclass
Directory - Basic operation
Rename
Copy
Move
Delete
- rename(new_name: str) None [source]
Rename directory
- Parameters:
new_name (str) – Name only (not the entire path)
- move(dst: Path, content_only: bool = False) None [source]
Move entire directory
- Parameters:
dst (Path) – Destination
content_only (bool) – Only move content inside the folder (Default:
False
; Move entire folder)
- delete(entire: bool = False, *, based_on_time: bool = False, keep: Literal['Y', 'M', 'D'] = 'Y') None [source]
Deletes everything
- Parameters:
entire (bool) –
True
: Deletes the folder itselfFalse
: Deletes content inside only(Default:False
)based_on_time (bool) –
True
: Deletes everything exceptkeep
periodFalse
: Works normal(Default:False
)keep (Literal["Y", "M", "D"]) – Delete all file except current
Year
|Month
|Day
- class absfuyu.util.path.DirectoryArchiverMixin(source_path: str | Path, create_if_not_exist: bool = False)[source]
Bases:
AutoSubclass
Directory - Archiver/Compress
Compress
Decompress
Register extra zip format <staticmethod>
- compress(format: Literal['zip', 'tar', 'gztar', 'bztar', 'xztar'] = 'zip', delete_after_compress: bool = False, move_inside: bool = True) Path | None [source]
Compress the directory (Default: Create
.zip
file)- Parameters:
format (Literal["zip", "tar", "gztar", "bztar", "xztar"], optional) – By default
"zip"
-zip
: ZIP file (if thezlib
module is available). -tar
: Uncompressed tar file. Uses POSIX.1-2001 pax format for new archives. -gztar
: gzip’ed tar-file (if thezlib
module is available). -bztar
: bzip2’ed tar-file (if thebz2
module is available). -xztar
: xz’ed tar-file (if thelzma
module is available).delete_after_compress (bool, optional) – Delete directory after compress, by default
False
move_inside (bool, optional) – Move the commpressed file inside the directory, by default
True
- Returns:
Path – Compressed path
None – When fail to compress
Changed in version 5.1.0: Update funcionality (new parameter)
- static register_extra_zip_format() None [source]
This register extra extension for zipfile
Added in version 5.1.0
- decompress(format: Literal['zip', 'tar', 'gztar', 'bztar', 'xztar'] | None = None, delete_after_done: bool = False) None [source]
Decompress compressed file in directory (first level only)
- Parameters:
format (Literal["zip", "tar", "gztar", "bztar", "xztar"] | None, optional) – By default
None
-zip
: ZIP file (if thezlib
module is available). -tar
: Uncompressed tar file. Uses POSIX.1-2001 pax format for new archives. -gztar
: gzip’ed tar-file (if thezlib
module is available). -bztar
: bzip2’ed tar-file (if thebz2
module is available). -xztar
: xz’ed tar-file (if thelzma
module is available).delete_after_done (bool, optional) – Delete compressed file when extracted, by default
False
Added in version 5.1.0
- class absfuyu.util.path.DirectoryOrganizerMixin(source_path: str | Path, create_if_not_exist: bool = False)[source]
Bases:
AutoSubclass
Directory - File organizer - SOON
- class absfuyu.util.path.DirectoryTreeMixin(source_path: str | Path, create_if_not_exist: bool = False)[source]
Bases:
AutoSubclass
- list_structure(*ignore: str) str [source]
List folder structure
- Parameters:
ignore (str) – Tuple contains patterns to ignore
- Returns:
Directory structure
- Return type:
str
Example (For typical python library):
>>> test = Directory(<source path>) >>> test.list_structure( "__pycache__", ".pyc", "__init__", "__main__", ) ...
- class absfuyu.util.path.FileOrFolderWithModificationTime(path: Path, modification_time: datetime)[source]
Bases:
NamedTuple
File or Folder with modification time
- Parameters:
path – Original path
modification_time – Modification time
Added in version 3.3.0
- path: Path
Alias for field number 0
- modification_time: datetime
Alias for field number 1
- class absfuyu.util.path.DirectoryInfo(creation_time: datetime, modification_time: datetime)[source]
Bases:
NamedTuple
Information of a directory
Added in version 3.3.0
Deprecated in version 5.1.0: Support for ``DirectoryInfoMixin`` which is also deprecated
- creation_time: datetime
Alias for field number 0
- modification_time: datetime
Alias for field number 1