A Python script that monitors a folder in real-time and logs whenever files are added, deleted, or modified.
Ideal for developers, system admins, or anyone who wants to track file system changes automatically.
- Real-time monitoring of a folder
- Detects file creation, deletion, and modification
- Automatically logs all events with timestamps
- Saves logs to a file:
folder_activity.log - Works on Windows, macOS, and Linux
- Lightweight — only requires the
watchdoglibrary
When you add, remove, or modify files, a log entry is created automatically:
2025-10-31 10:42:11 - File created: /Users/Downloads/photo.jpg
2025-10-31 10:43:08 - File modified: /Users/Downloads/report.pdf
2025-10-31 10:44:22 - File deleted: /Users/Downloads/old_notes.txt
-
Monitors a target folder using the
watchdoglibrary. -
Detects three types of file system events:
- Created
- Deleted
- Modified
-
Records each event with a timestamp in a log file named
folder_activity.log. -
Runs continuously until manually stopped with Ctrl + C.
Download or copy folder_monitor.py to your computer.
Use pip to install the watchdog library:
pip install watchdogOpen a terminal or command prompt and execute:
python folder_monitor.pyYou’ll be prompted to enter the folder you want to monitor. If you press Enter without typing anything, it defaults to your Downloads folder.
=== Folder Activity Monitor ===
Enter the folder path to monitor [/Users/deepak/Downloads]:
All activity is logged in folder_activity.log in the same directory as the script.
| Option | Description |
|---|---|
| Folder to Monitor | Any valid directory path. Defaults to the user's Downloads folder. |
| Recursive | Set recursive=True in the script to monitor subfolders. |
| Log File | Automatically created as folder_activity.log in the script’s directory. |
- The script only tracks file-level changes by default (not folders).
- Press Ctrl + C to stop monitoring gracefully.
- Ensure you have read/write permissions for the folder you monitor.
- For performance, avoid using it on extremely large folders with thousands of files.