Created
May 22, 2013 17:19
-
-
Save guanqun/5629270 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
files = [] | |
for (root, dirnames, filenames) in os.walk('.'): | |
if len(filenames) != 0: | |
for one in filenames: | |
files.append(os.path.join(root, one)) | |
isPng = re.compile(r'.*\.png$') | |
isHdPng = re.compile(r'.*-hd\.png$') | |
pngFiles = [] | |
for f in files: | |
if isPng.match(f): | |
pngFiles.append(f) | |
hdPngFiles = [] | |
for f in files: | |
if isHdPng.match(f): | |
hdPngFiles.append(f) | |
sdPngFiles = [] | |
for f in pngFiles: | |
if f not in hdPngFiles: | |
sdPngFiles.append(f) | |
# check whether these two lists cover the same files | |
excludeFiles = [] | |
for f in sdPngFiles: | |
correspondingFile = re.sub(r'\.png$', r'-hd.png', f) | |
if correspondingFile not in hdPngFiles: | |
print f + ' doesn\'t have a corresponding hd file ' + correspondingFile | |
excludeFiles.append(f) | |
for f in hdPngFiles: | |
correspondingFile = re.sub(r'-hd\.png$', r'.png', f) | |
if correspondingFile not in sdPngFiles: | |
print f + ' doesn\'t have a corresponding normal file ' + correspondingFile | |
excludeFiles.append(f) | |
print 'Excluded Files:' | |
for f in excludeFiles: | |
if f in sdPngFiles: | |
sdPngFiles.remove(f) | |
if f in hdPngFiles: | |
hdPngFiles.remove(f) | |
print ' ' + f | |
# replace! | |
for f in hdPngFiles: | |
correspondingFile = re.sub(r'-hd\.png$', r'.png', f) | |
os.rename(f, correspondingFile) | |
print 'Done!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment