import time from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler class MyHandler(FileSystemEventHandler): def on_modified(self, event): if event.is_directory: print("Directory modified:", event.src_path) else: print("File modified:", event.src_path) if __name__ == "__main__": event_handler = MyHandler() observer = Observer() observer.schedule(event_handler, path='.') observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join()This code uses the `Observer` class to monitor the current directory for file modifications. When a modification occurs, the `on_modified` method of the `MyHandler` class is called, which prints a message indicating whether the modified item was a file or directory. The `join` method is used to block the main thread until the observer's thread terminates. The package library used in this example is `watchdog`.