Skip to content

Instantly share code, notes, and snippets.

@dgrant
Created April 27, 2015 01:10
Show Gist options
  • Save dgrant/dd6fd98ae48f5a42d117 to your computer and use it in GitHub Desktop.
Save dgrant/dd6fd98ae48f5a42d117 to your computer and use it in GitHub Desktop.
Script to verify that destination is not mising any photos from source
#!/usr/bin/python
""" Script to verify that destination is not mising any files from source """
import os
import sys
FILE_TYPES = ['.NEF', '.JPG', '.MTS']
def get_all_files(path, filters=()):
"""
Iterates over all files in path
filters is a list of file extensions to match (uppercase)
"""
for root, _, filelist in os.walk(path):
for name in filelist:
if os.path.splitext(name)[1].upper() in filters:
yield os.path.join(root, name)
def verify_no_missing_files(path1, path2):
"""
Verifies that there are no files in path1 that are missing from path2
"""
print "Note: this only looks for the following extensions:", \
",".join(FILE_TYPES)
files1_dict = {}
all_files1 = list(get_all_files(path1, FILE_TYPES))
files1 = set([os.path.split(f)[1].lower() for f in all_files1])
for f in all_files1:
key = os.path.split(f)[1].lower()
files1_dict[key] = f
files2 = set([os.path.split(f)[1].lower() \
for f in get_all_files(path2, FILE_TYPES)])
print "Path 1:", path1, "({0} files)".format(len(files1))
print "Path 2:", path2, "({0} files)".format(len(files2))
missing_files = list(files1 - files2)
missing_files.sort()
print "The following files from Path 1 are missing in Path 2:"
for missing_file in missing_files:
print files1_dict[missing_file]
def main():
"""
Main entry point. Parses command line options
"""
path1 = os.path.abspath(sys.argv[1])
path2 = os.path.abspath(sys.argv[2])
verify_no_missing_files(path1, path2)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment