File system
Classes
FileSystem class which creates a convenient overview of a given folder and the files within it |
Module Contents
- class FileSystem(path_folder, extension=None)
FileSystem class which creates a convenient overview of a given folder and the files within it
Initialize FileSystem instance which creates a convenient overview of a given folder and the files within it
- Parameters:
path_folder (str | Path) – path of folder for which a FileSystem instance will be created
extension (Optional[str], optional) – extension of specific files to include in the FileSystem instance. Defaults to None, which returns all files path_folder regardless of extension.
- folderpath
- files
- static validate_path(path_to_check)
Checks if the given path exists
- Parameters:
path_to_check (str | Path) – path to either a file or a folder
- Raises:
FileNotFoundError – raised if the file/folder was not found
- Returns:
Path object for the validated path
- Return type:
Path
- static find_files_in_dir(path_to_dir, extension=None)
Find all files with a specified extension in a folder and its subfolders. Note: files starting with ~$ are ignored since these are generally temporary files
- Parameters:
path_to_dir (str | Path) – folder to search in
extension (str, None) – extension without the dot (e.g. “txt” instead of “.txt”). If None is passed all files in dir, regardless of extension, are returned
- Returns:
list of paths to the found files in the dir. Returns None if no files were found.
- Return type:
list[Path]
- static find_subfolders(path_to_dir)
Find all subfolders within a parent folder
- Parameters:
path_to_dir (str | Path) – folder to search in
- Returns:
list of paths to the found subfolders in the dir.
- Return type:
list[Path]