def comparedirs(dir1, dir2): print 'Comparing', dir1, 'to', dir2 files1 = os.listdir(dir1) files2 = os.listdir(dir2) unique1 = unique(files1, files2) unique2 = unique(files2, files1) dirdiff.reportdiffs(unique1, unique2, dir1, dir2)
def comparedirs(dir1, dir2): print 'Comparing', dir1, 'to', dir2 files1 = glob.glob(os.path.join(dir1, '*')) files2 = glob.glob(os.path.join(dir2, '*')) tail = lambda x: os.path.split(x)[1] files1 = map(tail, files1) files2 = map(tail, files2) unique1 = dirdiff.unique(files1, files2) unique2 = dirdiff.unique(files2, files1) dirdiff.reportdiffs(unique1, unique2, dir1, dir2)
def comparedirs(dir1, dir2): print 'Comparing', dir1, 'to', dir2 files1 = os.listdir(dir1) files2 = os.listdir(dir2) files1.sort() files2.sort() if files1 == files2: print 'Directory lists are identical' else: unique1 = dirdiff.unique(files1, files2) unique2 = dirdiff.unique(files2, files1) dirdiff.reportdiffs(unique1, unique2, dir1, dir2)
def comparedirs(dir1, dir2): print 'Comparing', dir1, 'to', dir2 files1 = os.popen('ls %s' % dir1).readlines() files2 = os.popen('ls %s' % dir2).readlines() tail = lambda x: x[:-1] files1 = map(tail, files1) files2 = map(tail, files2) unique1 = dirdiff.unique(files1, files2) unique2 = dirdiff.unique(files2, files1) dirdiff.reportdiffs(unique1, unique2, dir1, dir2)
#!/bin/env python ######################################################## # use: python dirdiff.py <dir1-path> <dir2-path> # compare two directories to find files that exist # in one but not the other; this version uses the # os.listdir and os.exists, rathher than list diffs; ######################################################## import os, dirdiff dir1, dir2 = dirdiff.getargs() print 'Comparing', dir1, 'to', dir2 unique1 = [] for file in os.listdir(dir1): if not os.path.exists(os.path.join(dir2, file)): unique1.append(file) unique2 = [] for file in os.listdir(dir2): if not os.path.exists(os.path.join(dir1, file)): unique2.append(file) dirdiff.reportdiffs(unique1, unique2, dir1, dir2)