Skip to content

Instantly share code, notes, and snippets.

@dasl-
Created September 28, 2024 20:29
Show Gist options
  • Save dasl-/fbf560ff95db034e6daf8e51066bdb2f to your computer and use it in GitHub Desktop.
Save dasl-/fbf560ff95db034e6daf8e51066bdb2f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import argparse
import os
def parseArgs():
parser = argparse.ArgumentParser(
description=('Iterates through files in a directory. If there is a file with the name ' +
'MY_FILENAME.MOV _and_ MY_FILENAME.HEIC, it deletes MY_FILENAME.MOV. For culling iOS live photos.'),
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument('--directory', dest='directory', action='store', required = True,
help='The directory through which to iterate.')
parser.add_argument('--wet-run', dest='is_wet_run', action='store_true', default = False, required = False,
help='The directory through which to iterate.')
args = parser.parse_args()
return args
def main():
file_paths = {}
for f in os.listdir(args.directory):
file_path = os.path.join(args.directory, f).lower()
if os.path.isfile(file_path):
file_paths[file_path] = True
file_paths_to_delete = []
for key in file_paths:
if key.endswith('.mov') and key[:-4] + '.heic' in file_paths:
file_paths_to_delete.append(key)
msg_prefix = 'Would have deleted'
if args.is_wet_run:
msg_prefix = 'Deleting'
msg = f"{msg_prefix} {len(file_paths_to_delete)} files:\n" + "\n".join(file_paths_to_delete)
print(msg)
if args.is_wet_run:
for file_to_delete in file_paths_to_delete:
os.remove(file_to_delete)
print("Done!")
args = parseArgs()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment