Inilah skrip python saya untuk menghapus cr2's w / oa jpeg.
Itu mencari secara rekursif dalam direktori saat ini, "." Ini mempertimbangkan semua gambar di semua folder.
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")