Skip to content

Instantly share code, notes, and snippets.

@revolc
Last active December 17, 2015 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revolc/5559280 to your computer and use it in GitHub Desktop.
Save revolc/5559280 to your computer and use it in GitHub Desktop.
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__:
process_and_remove_at_2x_image()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment