# file_type.py # Identify type of file: file, directory, link, broken link import errno import os from pathlib import Path class FileType(): @classmethod def get_file_type(cls, filename): # Return type of file ("file", "dir", "link", "broken-link", "other") p = Path(filename) if not p.exists(): if p.is_symlink(): return "broken-link" else: raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), filename) if p.is_symlink(): return "symlink" if p.is_dir(): return "directory" elif p.is_file(): return "file" return "other"