Created
September 2, 2014 07:28
-
-
Save dgrant/2d32a9cba23c6dddc5c1 to your computer and use it in GitHub Desktop.
Script to verify that destination is not mising any files from source Usage: exist_check.py <src> <dest>
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
#!/usr/bin/python | |
""" | |
Script to verify that destination is not mising any files from source | |
Usage: exist_check.py <src> <dest> | |
""" | |
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 = set([os.path.split(f)[1] \ | |
for f in get_all_files(path1, FILE_TYPES)]) | |
files2 = set([os.path.split(f)[1] \ | |
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 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