views:

69

answers:

2

Hello How would you go about testing to see if 2 folders contain the same files, and then to be able to manipulate ONLY the file which is new.

A = listdir('C:/')
B = listdir('D:/')

If A==B

...

I know this could be used to test if directories are different but is there a better way? And if A and B are the same, except B has one more file than A, how do i use just the new file?

Thank you, i hope my question isnt confusing

+4  A: 
A = set(os.listdir('C:\\'))
B = set(os.listdir('D:\\'))

print 'Files in A but not in B:', A - B
print 'Files in B but not in A:', B - A
nosklo
+8  A: 

http://docs.python.org/library/filecmp.html

http://docs.python.org/library/filecmp.html#the-dircmp-class

import filecmp
compare = filecmp.dircmp( "C:/", "D:/" )
for f in compare.left_only:
    print "C: new", f
for f in compare.right_only:
    print "D: new", f
S.Lott