import os import sys def remove_symlinks(root_dir, output_file="removed_symlinks.txt"): removed = [] for dirpath, _, filenames in os.walk(root_dir): for fname in filenames: fpath = os.path.join(dirpath, fname) try: if os.path.islink(fpath): os.unlink(fpath) removed.append(fpath) except Exception as e: print(f"Error removing symlink {fpath}: {e}") with open(output_file, "w", encoding="utf-8") as f: for path in removed: f.write(path + "\n") print(f"Removed {len(removed)} symlinks. Results saved to {output_file}") if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python discard_media.py [output_file]") else: root = sys.argv[1] out_file = sys.argv[2] if len(sys.argv) > 2 else "removed_symlinks.txt" remove_symlinks(root, out_file)