import sys,os
import filecmp
def testdiff(leftdir,rightdir):
rf = filecmp.dircmp(leftdir,rightdir)
_cmpdir(rf)
delete_files = []
copy_files = []
def _cmpdir(r):
global delete_files,copy_files
delete_files += [os.path.join(r.left,l) for l in r.left_only if not l.startswith('.') ]
copy_files += [os.path.join(r.left,l)+' '+os.path.join(r.right,l )for l in r.right_only if not l.startswith('.')]
copy_files += [os.path.join(r.left,l)+' '+os.path.join(r.right,l) for l in r.diff_files if not l.startswith('.')]
for sd in r.subdirs:
if sd.find(".svn")==-1 :
testdiff(os.path.join(r.left,sd),os.path.join(r.right,sd))
print os.path.join(r.left,sd)
print os.path.join(r.right,sd)
else:
pass
return delete_files,copy_files
def printcopyfile(copyfile):
global delete_files,copy_files
for log in copy_files:
output(log,"copylist")
def output(log,type):
txtlog = log
recordfile = os.path.join(sys.path[0]+'/'+type)
try:
fp = open(recordfile , "a+")
print >>fp , txtlog
fp.close()
except:
pass
def main():
if len(sys.argv)>=3:
testdiff(sys.argv[1],sys.argv[2])
else:
print "argv error"
printcopyfile(copy_files)
print delete_files
print copy_files
if __name__ == "__main__":
main()
介绍请看 http://blog.csdn.net/csapr1987/article/details/7637933
生成copylist文件,