/IronPython_Main/Languages/IronPython/Scripts/CompareDirs.py

# · Python · 46 lines · 26 code · 6 blank · 14 comment · 11 complexity · 37ecaa985c3630f28feee88a900fc034 MD5 · raw file

  1. #####################################################################################
  2. #
  3. # Copyright (c) Microsoft Corporation. All rights reserved.
  4. #
  5. # This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  6. # copy of the license can be found in the License.html file at the root of this distribution. If
  7. # you cannot locate the Apache License, Version 2.0, please send an email to
  8. # ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. # by the terms of the Apache License, Version 2.0.
  10. #
  11. # You must not remove this notice, or any other, from this software.
  12. #
  13. #
  14. #####################################################################################
  15. import sys,nt
  16. sys.path.append(nt.environ['IP_ROOT'] + '\\External\\Regress\\Python24\\Lib')
  17. import filecmp
  18. def compare_dirs(dir1, dir2):
  19. "Tests whether two folders, including all their contents and subdirectories are identical or not (True == they're the same, False == they are not the same)"
  20. dc = filecmp.dircmp(dir1,dir2)
  21. if len(dc.funny_files) > 0 or len(dc.left_only) > 0 or len(dc.right_only) > 0 or len(dc.diff_files) > 0:
  22. dc.report()
  23. return False
  24. else:
  25. for subdir in dc.common_dirs:
  26. if not compare_dirs(dir1 + "\\" + subdir, dir2 + "\\" + subdir):
  27. return False
  28. return True
  29. def main():
  30. if len(sys.argv)!=3:
  31. print 'Usage: CompareDirs <dir1> <dir2>'
  32. sys.exit(-1)
  33. if compare_dirs(sys.argv[1],sys.argv[2]):
  34. print "The directories are identical"
  35. sys.exit(0)
  36. else: #the part that differed is explained via dircmp.report() above
  37. print "The directories differ"
  38. sys.exit(1)
  39. if __name__=="__main__":
  40. main()