Skip to content

Instantly share code, notes, and snippets.

@MattWoodhead
Created September 19, 2017 19:59
Show Gist options
  • Save MattWoodhead/499dea2596fb63193d5f4c65b304d484 to your computer and use it in GitHub Desktop.
Save MattWoodhead/499dea2596fb63193d5f4c65b304d484 to your computer and use it in GitHub Desktop.
A function to see if a file has changed
import os
FILE = "test.txt"
def file_changed(file):
""" Checks the windows file attributes to see if a file has been updated """
new_change_time = None
last_change_time = None
while new_change_time == last_change_time:
if last_change_time is None:
last_change_time = os.stat(file).st_mtime # time of previous content modification
new_change_time = os.stat(file).st_mtime # time of most recent content modification
# when the while-loop becomes false - i.e. the file has changed
return True
if file_changed(FILE):
os.startfile(FILE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment