pretty

Saturday, April 28, 2012

Compare directories and generate diff

A small directory comparison script

This only works on a flat file structure no subdirs.
The comparison is only one way.
Files thats found in new will be copied to a separate directory

import filecmp
import shutil

old = "/tmp/old/"
new = "/tmp/new/"
diff_new = "/tmp/diff/"

new_list = filecmp.dircmp(old,new).right_only

for newfile in new_list:
shutil.copy(new+newfile,diff_new+newfile)
I might get back with at more complex script that handles recursion and two way diff

No comments:

Post a Comment