Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
python script that keep @2x file with the name of low definition file
#!/usr/bin/env python
import os
image_file_types = ['.jpg', '.png']
def is_image_file(file_name):
fileName, fileExt = os.path.splitext(file_name)
for type in image_file_types:
if type.lower() == fileExt.lower():
return True
return False
def is_at_2x_file(file_name):
fileName, fileExt = os.path.splitext(file_name)
return fileName.endswith("@2x")
def process_and_remove_at_2x_image():
current_dir = os.getcwd()
dir_list = []
file_list = []
for root, dirs, files in os.walk(current_dir):
for f in files:
if (is_image_file(f)):
file_list.append(os.path.join(root, f))
for f in file_list:
fileName, fileExt = os.path.splitext(f)
if is_at_2x_file(fileName):
normal_fileName = fileName[:-3]
normal_file = normal_fileName + fileExt
if (os.path.exists(normal_file)):
os.rename(f, normal_file)
if "__main__" == __name__:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.