Path and Folder Methods

Useful paths and folders, search in folders and temporary folder helper methods.

Warning

Folder paths are for OSX only.

Note

Special folders like Google Drive and OneDrive may not be available in your directories. Or your directory structure may be different.

class ozcore.core.path.folders.Folder[source]
Essential folder paths as posixpath:
  • Downloads

  • gDrive

  • iCloud

  • OneDrive

Hint

Search for a folder with glob option

Apps folder in this package:
  • folders in apps as posixpath enum

  • list of folders in apps folder

Example, Search Downloads folder:

from ozcore import core
core.folder.search(path=core.folder.Downloads, file="the_file_searched.xl**")

Example, is_a_subfolder:

from ozcore import core
core.folder.is_a_subfolder(path_to_check=Path("."), parent_folder=core.BASE_DIR)
property Downloads

MacOS Downloads folder path

Returns

POSIXPATH to Downloads folder

property gDrive

Google Drive folder path

Returns

POSIXPATH to gDrive

property iCloud

iCloud folder path

Returns

POSIXPATH to iCloud

property OneDrive

OneDrive folder path

Returns

POSIXPATH to OneDrive

search(path, file)[source]

search files in a given folder path

Parameters
  • path – a str or posixpath path

  • file – str, file to search; searches as glob, e.g. /.json”**

Returns

list, files in POSIXPATH type

usage:

from ozcore import core
core.folder.search(core.folder.gDrive.joinpath("folder name"), "*.xlsx")
is_a_subfolder(path_to_check: pathlib.PosixPath, parent_folder: pathlib.PosixPath)[source]

check if a given path is in parent folder

Parameters
  • path_to_check – posixpath, a path to match with base folder

  • parent_folder – posixpath, the base aka parent folder

Returns

boolean

check_path(path: Union[str, pathlib.PosixPath], is_file: bool = False)pathlib.PosixPath[source]

Checks the given path param, converts it to an absolute path

Warning

All relative paths are ignored and Exception will be raised.

Note

This method checks the type of the arguments and raise Exception if not satisfied.

Parameters
  • path – str|PosixPath, can be Pathlike path or a relative path

  • is_file – bool, default False, False: a directory, True: a file

Returns

Absolute PosixPath; checks if path exists.