Created
September 19, 2017 19:59
-
-
Save MattWoodhead/499dea2596fb63193d5f4c65b304d484 to your computer and use it in GitHub Desktop.
A function to see if a file has changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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