Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. #
  4. # Copyright (c) 2008 Doug Hellmann All rights reserved.
  5. #
  6. """Compare files in two directories.
  7. """
  8.  
  9. __version__ = "$Id$"
  10. #end_pymotw_header
  11.  
  12. import filecmp
  13. import os
  14.  
  15. # Determine the items that exist in both directories
  16. d1_contents = set(os.listdir('example/dir1'))
  17. d2_contents = set(os.listdir('example/dir2'))
  18. common = list(d1_contents & d2_contents)
  19. common_files = [ f
  20. for f in common
  21. if os.path.isfile(os.path.join('example/dir1', f))
  22. ]
  23. print 'Common files:', common_files
  24.  
  25. # Compare the directories
  26. match, mismatch, errors = filecmp.cmpfiles('example/dir1',
  27. 'example/dir2',
  28. common_files)
  29. print 'Match :', match
  30. print 'Mismatch:', mismatch
  31. print 'Errors :', errors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement