Welcome to EZPaths’s documentation!

class ezpaths.Path(path_str: Optional[str] = None)

This class provides shorthand methods for common os.path functions The motivation for development that complex one-liners with os.path can be hard to read. This is intended to make complex one-liners easy to understand without comments.

__init__(path_str: Optional[str] = None)

Constructor method

Parameters

path_str (str, optional) – The path string to be stored, defaults to None

__add__(other) → ezpaths.path.Path

Creates the joined path appending other (RHS) to self. Does not modify self. Same as __truediv__.

Parameters

other (Either a Path or string) – The path segment to be joined

Returns

Returns the resulting Path object

Return type

Path

__truediv__(other) → ezpaths.path.Path

Creates the joined path appending other (RHS) to self. Does not modify self. Same as __add__.

Parameters

other (Either a Path or string) – The path segment to be joined

Returns

Returns the resulting Path object

Return type

Path

__str__() → str

Return the stored path string.

Returns

String of target path.

Return type

str

__repr__() → str

Returns the type and path string in instance brackets.

Returns

String representation of self.

Return type

str

__bool__() → bool

Checks if path exists as either a file or directory.

Returns

True if exists else False.

Return type

bool

__eq__(other) → bool

Checks if the absolute path of self and other are identical.

Parameters

other (Either a Path or string) – The path to be compared

Returns

True if identical paths else False

Return type

bool

dir(extra: int = 0) → ezpaths.path.Path

Returns path object targeting parent directory of self.

Parameters

extra (int, optional) – Number of extra levels to ascend recursively, defaults to 0

Returns

The parent directory path

Return type

Path

dirname() → str

Returns the name of the last directory, with or without file at end of path.

Returns

The name of the last directory in self._path

Return type

str

split() -> (<class 'str'>, <class 'str'>)

Return name and extension separately.

Returns

The name and extension of the file.

Return type

tuple(name: str, ext: str)

ext() → str

Returns just the file extension.

Returns

File extension

Return type

str

name() → str

Returns the last file or dir name without extension.

Returns

Last file or dir name

Return type

str

filename() → str

Returns the last file or dir name with extension.

Returns

Last file or dir name

Return type

str

to_sys(index: int = 0) → None

Adds self to sys.path list. Will insert at front by default. Inserting at front makes it the first path checked when importing.

Parameters

index (int, optional) – Index to be inserted at in sys.path list, defaults to 0

Returns

None

Return type

None

touch() → bool

Implement the touch feature for this Path

Returns

True always.

Return type

bool

delete() → bool

Deletes this file from the disk

Returns

True if the file has been successfully deleted, False otherwise.

Return type

bool

rename(new_name: str) → bool

New name for the file or the directory in the path

Parameters

new_name (str) – New name for the filename.

Returns

True if the file has been successfully renamed, False otherwise.

Return type

bool

copy(destination: Optional[ezpaths.path.Path] = None, suffix: str = 'copy') → ezpaths.path.Path

Copies this file/folder to the given destination path.

Parameters
  • destination (Path, optional) – The destination path this file needs to be copied to. If None, a new copy with the suffix is created in the same location.

  • suffix – Suffix of the copied file when the same filename exists in the destination folder. Defaults to “copy”.

Returns

Path instance of the destination.

Return type

Path

move(destination: ezpaths.path.Path) → ezpaths.path.Path

Moves this file or folder to the given destination

Parameters

destination (Path.) – Path to be moved to.

Returns

Path instance of the moved file/folder. None if failed.

Return type

Path

mkdirs() → bool

Creates a directory recursively. That means while making leaf directory if any intermediate-level directory is missing, this method will create them all.

Returns

True if successful, False otherwise.

Return type

bool

__weakref__

list of weak references to the object (if defined)

Indices and tables