Python from pathlib import Path path = Path("path/to/file.txt") if path.exists(): else: if path.is_file(): elif path.is_dir(): with path.open() as f: content = f.read() print(content) for p in path.glob("**/*"): print(p)