다음은 cr2의 w / oa jpeg를 삭제하는 파이썬 스크립트입니다.
현재 디렉토리 "."내에서 재귀 적으로 검색합니다. 모든 폴더의 모든 이미지를 고려합니다.
import os
import sys
#Searches through the current directory, recursively, looking for any raw
#and jpeg files. It enumerates the jpegs it finds, without the extension, and
#then enumerates the raw files it finds. If it finds a raw file for which no
#jpeg exists, then it deletes the raw file.
#
# This WILL NOT WORK, if there are files with repeated file numbers.
# this will NOT be an issue if there's only one camera.
# A dict of filename: (rawpath, jpegpath)
files_seen = {}
for (cur_dir, subdirs, files) in os.walk("."):
for file in files:
fname, fext = os.path.splitext(file)
fext = fext.lower()
if (fext == ".jpg"):
content = files_seen.setdefault(fname, [None, None])
# if it is then filenames have du'ped
assert(content[1] is None)
content[1] = os.path.join(cur_dir, file)
elif (fext == ".cr2"):
content = files_seen.setdefault(fname, [None, None])
assert(content[0] is None)
content[0] = os.path.join(cur_dir, file)
#at the end, we look for raw files without a jpeg,
for key in files_seen:
(raw_path, jpeg_path) = files_seen[key]
if jpeg_path is None:
print("Deleting: %s" % raw_path)
#os.system("pause.exe")
os.unlink(raw_path)
print("Done")
os.system("pause.exe")