toolregistry.hub.filesystem module¶
File system operations module providing file and directory utilities.
This module contains the FileSystem class and convenience functions for: - File and directory existence checks - File reading/writing - Directory listing - File/directory copy/move/delete - Path manipulation
Example
>>> from toolregistry.hub import FileSystem
>>> fs = FileSystem()
>>> fs.create_dir('new_dir')
# Note: create_file is part of FileSystem, write_file is in FileOps
>>> fs.create_file('new_dir/file.txt', 'content')
>>> fs.list_dir('new_dir')
['file.txt']
- class toolregistry.hub.filesystem.FileSystem[source]¶
Bases:
object
Provides file system operations related to structure, state, and metadata.
- static exists(path: str) bool [source]¶
Checks if a path exists.
- Parameters:
path – The path string to check.
- Returns:
True if path exists, False otherwise
- static is_file(path: str) bool [source]¶
Checks if a path points to a file.
- Parameters:
path – The path string to check.
- Returns:
True if the path points to a file, False otherwise.
- static is_dir(path: str) bool [source]¶
Checks if a path points to a directory.
- Parameters:
path – The path string to check.
- Returns:
True if the path points to a directory, False otherwise.
- static list_dir(path: str, depth: int = 1, show_hidden: bool = False) List[str] [source]¶
Lists contents of a directory up to a specified depth.
- Parameters:
path – The directory path string to list.
depth – Maximum depth to list (default=1). Must be >= 1.
show_hidden – If False, filters out hidden files/directories. On Unix-like systems (Linux, macOS), this means names starting with ‘.’. On Windows, this means files/directories with the ‘hidden’ attribute set, as well as names starting with ‘.’. (default is False).
- Returns:
List of relative path strings of items in the directory up to the specified depth.
- Raises:
ValueError – If depth is less than 1.
FileNotFoundError – If the path does not exist or is not a directory.
- static create_file(path: str) None [source]¶
Creates an empty file or updates the timestamp if it already exists (like ‘touch’).
- Parameters:
path – The file path string to create or update.
- static copy(src: str, dst: str) None [source]¶
Copies a file or directory.
- Parameters:
src – Source path string.
dst – Destination path string.
- static move(src: str, dst: str) None [source]¶
Moves/renames a file or directory.
- Parameters:
src – Source path string.
dst – Destination path string.
- static delete(path: str) None [source]¶
Deletes a file or directory recursively.
- Parameters:
path – Path string to delete.
- static get_size(path: str) int [source]¶
Gets file/directory size in bytes (recursive for directories).
- Parameters:
path – Path string to check size of.
- Returns:
Size in bytes.
- Raises:
FileNotFoundError – If the path does not exist.
- static get_last_modified_time(path: str) float [source]¶
Gets the last modified time of a file or directory.
- Parameters:
path – Path string to the file or directory.
- Returns:
Last modified time as a Unix timestamp (float).
- Raises:
FileNotFoundError – If the path does not exist.
- static join_paths(*paths: str) str [source]¶
Joins multiple path components into a normalized string path.
- Parameters:
*paths – One or more path component strings.
- Returns:
Joined and normalized path string.
- static get_absolute_path(path: str) str [source]¶
Gets the absolute path as a normalized string.
- Parameters:
path – Path string to convert.
- Returns:
Absolute path string.
- static create_dir(path: str, parents: bool = True, exist_ok: bool = True) None [source]¶
Creates a directory, including parent directories if needed (defaults to True).
- Parameters:
path – Directory path string to create.
parents – Create parent directories if needed (default=True).
exist_ok – Don’t raise error if directory exists (default=True).