darf.src.io.files module

files module

Use this module to handle files

class darf.src.io.files.FileHandler(filepath: str, create: bool = True)

Bases: object

FileHandler. Class to manage single files

classmethod detect(in_dir: DirectoryHandler) List[Self]

detect. Get the list of files in a directory as FileHandlers

Parameters:

dir (DH) – dir

Return type:

List[FileHandler]

static exists(filepath: str, use_glob: bool = False) bool

exists. Return if a file exists or not

Parameters:
  • filepath (str) – filepath

  • use_glob (bool) – if true the file will be searched using glob instead of os.path.exists

Return type:

bool

property filename: str

filename.

Returns:

the name of the file

Return type:

str

property folder_path: str

folder_path. Get the folder path of a file

Return type:

str the path to the file, without the file, only the folders

get(extension: str) str

get. Permits to get a file path with the same file name as the handled one plus an appendix, remember the type of the file, the part after the ‘.’ will be removed

Parameters:

extension (str) – string to use instead of the default desinence of the file

Return type:

str the filepath modified

static get_wildcard(filepath: str) List[str]

get_wildcard. Get the list of files that match the ‘filepath’ considering a possible wildcard

Parameters:

filepath (str) – filepath

Returns:

List of the files that match the wildcard

Return type:

List[str]

static hash_path(path: str, in_hash: str | None = None) str

hash_path. Get the path with the hash appended

Parameters:
  • path (str) – path

  • in_hash (Optional[str]) – hash given as input

Return type:

str

property path: str

path.

Returns:

the complete file path to the destination file

Return type:

str