from PyQt5.QtCore import QFileSystemWatcher def on_directory_changed(path): print("Directory changed: ", path) watcher = QFileSystemWatcher() watcher.addPath("/path/to/directory") watcher.directoryChanged.connect(on_directory_changed)
from PyQt5.QtCore import QFileSystemWatcher def on_file_changed(path): print("File changed: ", path) watcher = QFileSystemWatcher() watcher.addPath("/path/to/file1.txt") watcher.addPath("/path/to/file2.txt") watcher.fileChanged.connect(on_file_changed)In this example, we are creating a QFileSystemWatcher object and adding two files to watch. We then connect the fileChanged signal of the watcher to a custom function that will be called every time either of the watched files changes. This package/library is PyQt5.