यहाँ 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")