WillyLosverPL

[python] porównywanie dat modyfikacji - for Wilczek

Sep 23rd, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import sys
  5. import os
  6.  
  7. if len(sys.argv) != 3:
  8.     print "Nieprawidłowa liczba argumentów!"
  9.     print "Użycie: %s <plik1> <plik2>" % sys.argv[0]
  10.     sys.exit(1)
  11.  
  12. file1 = sys.argv[1]
  13. file2 = sys.argv[2]
  14.  
  15. try:
  16.     time1 = os.stat(file1).st_mtime
  17.     time2 = os.stat(file2).st_mtime
  18. except:
  19.     print "FAIL: nie można wykonać operacji stat"
  20.     sys.exit(1)
  21.  
  22. if time1 < time2:
  23.     print "%s jest starszy od %s" % (file1, file2)
  24. elif time1 == time2:
  25.     print "pliki zostały utworzone w tym samym czasie!"
  26. else:
  27.     print "%s jest starszy od %s" % (file2, file1)
Advertisement
Add Comment
Please, Sign In to add comment