Guest User

Untitled

a guest
Jan 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import os
  2. import platform
  3.  
  4. def creation_date(path_to_file):
  5. """
  6. Try to get the date that a file was created, falling back to when it was
  7. last modified if that isn't possible.
  8. See http://stackoverflow.com/a/39501288/1709587 for explanation.
  9. """
  10. if platform.system() == 'Windows':
  11. return os.path.getctime(path_to_file)
  12. else:
  13. stat = os.stat(path_to_file)
  14. try:
  15. return stat.st_birthtime
  16. except AttributeError:
  17. # We're probably on Linux. No easy way to get creation dates here,
  18. # so we'll settle for when its content was last modified.
  19. return stat.st_mtime
Add Comment
Please, Sign In to add comment