#!/usr/bin/env python3 import os from pathlib import Path this_dir = Path(__file__).parent.absolute() print(f"{this_dir=}") def show_all(d): for thing in d.glob("**/*"): print(thing) good_files = [this_dir / name for name in ("foo", "bar", "spam")] bad_file = this_dir / "eggs" # clean up from previous runs for path in good_files + [bad_file]: if path.is_symlink() or path.exists(): path.unlink() print("*** Before creating good files") show_all(this_dir) # create some good files for path in good_files: path.touch() # show newly created good print("*** After creating good files") show_all(this_dir) # now create a bad file bad_file.symlink_to("bad" * 200) # this fails print("*** After creating a bad file") show_all(this_dir)