Initial commit
This commit is contained in:
27
libs/filesearch.py
Normal file
27
libs/filesearch.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import time
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
from pathlib import Path
|
||||
downloads_path = Path.home() / "Downloads"
|
||||
|
||||
class NewFileHandler(FileSystemEventHandler):
|
||||
def on_created(self, event):
|
||||
if not event.is_directory:
|
||||
print(f"New file detected: {event.src_path}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
path_to_watch = downloads_path
|
||||
|
||||
event_handler = NewFileHandler()
|
||||
observer = Observer()
|
||||
observer.schedule(event_handler, path=path_to_watch, recursive=False)
|
||||
|
||||
print(f"Monitoring folder: {path_to_watch}...")
|
||||
observer.start()
|
||||
|
||||
try:
|
||||
while True:
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
observer.stop()
|
||||
observer.join()
|
||||
Reference in New Issue
Block a user