Created
January 25, 2022 06:09
-
-
Save Mahrjose/3b7f693567dc43c05f9c8343f74dc348 to your computer and use it in GitHub Desktop.
Track a file for changes and if file changes do something.
This file contains hidden or 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 | |
class FileTracker(object): | |
def __init__(self, filename): | |
self._cached_stamp = 0 | |
self.filename = filename | |
def is_modified(self): | |
stamp = os.stat(self.filename).st_mtime | |
if stamp != self._cached_stamp: | |
self._cached_stamp = stamp | |
return True | |
return False | |
def main(): | |
# Path of the file you're tracking | |
FILE = "./path/to/file" | |
print("Tracking...") | |
test = FileTracker(FILE) | |
while True: | |
if test.is_modified(): | |
# File you're tracking has changed, Do something... | |
pass | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment