| 12345678910111213141516171819202122232425262728293031 |
- import os
- import sys
- def delete_files_from_list(list_file, mock=False):
- with open(list_file, "r", encoding="utf-8") as f:
- files = [line.strip() for line in f if line.strip()]
- deleted = 0
- for file_path in files:
- try:
- if os.path.exists(file_path):
- if mock:
- print(f"[MOCK] Would delete: {file_path}")
- else:
- os.remove(file_path)
- print(f"Deleted: {file_path}")
- deleted += 1
- else:
- print(f"Not found: {file_path}")
- except Exception as e:
- print(f"Error deleting {file_path}: {e}")
- if mock:
- print(f"[MOCK] Total files that would be deleted: {len([f for f in files if os.path.exists(f)])}")
- else:
- print(f"Total deleted: {deleted}")
- if __name__ == "__main__":
- if len(sys.argv) < 2:
- print("Usage: python delete_media.py <file_list.txt> [--mock]")
- else:
- mock = "--mock" in sys.argv
- delete_files_from_list(sys.argv[1], mock=mock)
|