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.

exists(path)[source]

Checks if path exists

is_file(path)[source]

Checks if path is a file

is_dir(path)[source]

Checks if path is a directory

list_dir(path)[source]

Lists directory contents

create_file(path)[source]

Creates an empty file or updates timestamp (like touch)

copy(src, dst)[source]

Copies file/directory

move(src, dst)[source]

Moves/renames file/directory

delete(path)[source]

Deletes file/directory

get_size(path)[source]

Gets file/directory size in bytes

get_last_modified_time(path)[source]

Gets file last modified time (Unix timestamp)

join_paths(*paths)[source]

Joins path components

get_absolute_path(path)[source]

Gets absolute path as a string

create_dir(path)[source]

Creates directory

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).