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
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.