Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adrianjagielak/4217b3cae4cdc805ba50dd07cbbf3ce6 to your computer and use it in GitHub Desktop.
Save adrianjagielak/4217b3cae4cdc805ba50dd07cbbf3ce6 to your computer and use it in GitHub Desktop.
Google Photos Takeout keep only edited files
import os
def find_and_rename(directory):
# Traverse through all the files recursively
for foldername, subfolders, filenames in os.walk(directory):
for filename in filenames:
if "-edited." in filename or "-edite." in filename or "-edit." in filename or "-edi." in filename or "-ed." in filename or "-e." in filename or "-." in filename:
# Original name without the edited tag
original_name = filename.replace("-edited.", ".").replace("-edite.", ".").replace("-edit.", ".").replace("-edi.", ".").replace("-ed.", ".").replace("-e.", ".").replace("-.", ".")
original_path = os.path.join(foldername, original_name)
edited_path = os.path.join(foldername, filename)
# If the original counterpart exists, remove it
if os.path.exists(original_path):
os.remove(original_path)
# Rename the edited file to match the original name
os.rename(edited_path, original_path)
print(f"Renamed {edited_path} to {original_path}")
if __name__ == "__main__":
directory = input("Enter the directory path: ")
find_and_rename(directory)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment