hats.io.file_io.file_pointer#

Attributes#

Functions#

get_upath(→ upath.UPath)

Returns a UPath file pointer from a path string or other path-like type.

get_upath_for_protocol(→ upath.UPath)

Create UPath with protocol-specific configurations.

append_paths_to_pointer(→ upath.UPath)

Append directories and/or a file name to a specified file pointer.

does_file_or_directory_exist(→ bool)

Checks if a file or directory exists for a given file pointer

is_regular_file(→ bool)

Checks if a regular file (NOT a directory) exists for a given file pointer.

find_files_matching_path(→ list[upath.UPath])

Find files or directories matching the provided path parts.

directory_has_contents(→ bool)

Checks if a directory already has some contents (any files or subdirectories)

Module Contents#

BLOCK_SIZE = 32768[source]#
get_upath(path: str | pathlib.Path | upath.UPath) upath.UPath[source]#

Returns a UPath file pointer from a path string or other path-like type.

Parameters:
path: str | Path | UPath

base file path to be normalized to UPath

Returns:
UPath

Instance of UPath.

get_upath_for_protocol(path: str | pathlib.Path) upath.UPath[source]#

Create UPath with protocol-specific configurations.

If we access pointers on S3 and credentials are not found we assume an anonymous access, i.e., that the bucket is public.

Parameters:
path: str | Path | UPath

base file path to be normalized to UPath

Returns:
UPath

Instance of UPath.

append_paths_to_pointer(pointer: str | pathlib.Path | upath.UPath, *paths: str) upath.UPath[source]#

Append directories and/or a file name to a specified file pointer.

Parameters:
pointerstr | Path | UPath

FilePointer object to add path to

*paths: str

any number of directory names optionally followed by a file name to append to the pointer

Returns:
UPath

New file pointer to path given by joining given pointer and path names

does_file_or_directory_exist(pointer: str | pathlib.Path | upath.UPath) bool[source]#

Checks if a file or directory exists for a given file pointer

Parameters:
pointerstr | Path | UPath

File Pointer to check if file or directory exists at

Returns:
bool

True if file or directory at pointer exists, False if not

is_regular_file(pointer: str | pathlib.Path | upath.UPath) bool[source]#

Checks if a regular file (NOT a directory) exists for a given file pointer.

Parameters:
pointerstr | Path | UPath

File Pointer to check if a regular file

Returns:
bool

True if regular file at pointer exists, False if not or is a directory

find_files_matching_path(pointer: str | pathlib.Path | upath.UPath, *paths: str) list[upath.UPath][source]#

Find files or directories matching the provided path parts.

Parameters:
pointerstr | Path | UPath

base File Pointer in which to find contents

*paths: str

any number of directory names optionally followed by a file name. directory or file names may be replaced with * as a matcher.

Returns:
list[UPath]

New file pointers to files found matching the path

directory_has_contents(pointer: str | pathlib.Path | upath.UPath) bool[source]#

Checks if a directory already has some contents (any files or subdirectories)

Parameters:
pointerstr | Path | UPath

File Pointer to check for existing contents

Returns:
bool

True if there are any files or subdirectories below this directory.