24 lines
729 B
Python
24 lines
729 B
Python
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class FileMonitor:
|
|
def __init__(self, directory, callback):
|
|
self.directory = directory
|
|
self.callback = callback
|
|
|
|
def start_monitoring(self):
|
|
import time
|
|
import os
|
|
|
|
already_seen = set(os.listdir(self.directory))
|
|
while True:
|
|
time.sleep(1) # Check every second
|
|
current_files = set(os.listdir(self.directory))
|
|
new_files = current_files - already_seen
|
|
|
|
for new_file in new_files:
|
|
logger.info(f"monitor: new file found: {new_file}")
|
|
self.callback(os.path.join(self.directory, new_file))
|
|
|
|
already_seen = current_files |