WatchDog is a simple file monitoring utility built using Python and the watchdog library. It watches a specified folder (configurable, defaults to Downloads) for new or modified files whose names end with a configurable pattern (defaults to -watchdog before the file extension). When such files are detected, they are automatically moved to a target folder (configurable, defaults to Documents/watchdog_files).
- Monitors a folder for file creation, modification, or movement.
- Automatically moves files ending with a configurable pattern to a specified directory.
- Uses Python's
shutillibrary to move files efficiently and safely. - Easy to configure source and target folders.
- Cross-platform path handling using
os.path.expanduser. - Handles file conflicts by automatically renaming duplicates.
- Comprehensive error handling for permissions and OS errors.
- Python 3.x
watchdoglibrary
Install dependencies with:
pip install watchdog- Edit
main.pyto set your desiredFILE_PATTERN,watch_folderandtarget_folderpaths if needed. - Run the script:
python main.py- The script will keep running, watching for files. Press
Ctrl+Cto stop.
- Change the
FILE_PATTERNvariable to match your desired filename suffix (without the hyphen). - Change the
watch_folderandtarget_foldervariables inmain.pyto suit your needs. - The script only moves files whose names end with the configured pattern (defaults to
-watchdogbefore the extension).
- The script uses the
watchdoglibrary to monitor file system events in the specified folder. - When a file event is detected, it checks if the filename ends with the configured pattern.
- If it matches, the script uses Python's
shutil.move()function to move the file to the target directory. - If a file with the same name already exists, it automatically appends a counter to avoid conflicts.
- To watch for files ending with
-myfiles: SetFILE_PATTERN = "myfiles" - To use a different watch folder: Set
watch_folder = os.path.expanduser("~/Desktop") - To use a different target folder: Set
target_folder = os.path.expanduser("~/Documents/my_sorted_files")
This project is for personal use and learning purposes.