A lightweight, background Java utility that keeps your file system organized automatically.
The Problem: Your Downloads folder is a chaotic mess of PDFs, installers, images, and ZIPs.
The Solution: A "set it and forget it" Java program that watches specific folders and instantly sorts new files into categorized sub-directories.
- β‘ Zero-Latency Sorting: Uses Java's
WatchServiceAPI (Event-Driven) to detect file changes instantly without heavy CPU polling. - π‘οΈ Multi-Drive Support: Capable of monitoring folders across different local drives (C:, D:, External Volumes) simultaneously.
- π§ Intelligent Conflict Resolution: Never overwrites files. If
Resume.pdfexists, it automatically renames the new file toResume (1).pdf. - π§Ή Startup Cleanup: Performs a full scan and sort of existing files immediately upon launch.
- π Broad Format Support: Automatically categorizes:
- Images: .jpg, .png, .svg, .webp, etc.
- Documents: .pdf, .docx, .txt, .md
- Code: .java, .py, .js, .json
- Archives: .zip, .rar, .7z
- Installers: .exe, .msi, .dmg
This project demonstrates core Java software engineering concepts:
- Java NIO (New I/O): For efficient file system manipulation.
- Concurrency: Handling blocking event listeners while managing file operations.
- Robust Error Handling: Manages "Overflow" events and file locks (race conditions) during active downloads.
- Modular Design: Clean separation between the "Watch" logic and the "Sort" logic.
- Java Development Kit (JDK) 8 or higher.
- IntelliJ IDEA (Recommended) or any Java IDE.
- Clone the repository:
- Open in IntelliJ IDEA.
- Configure your folders:
Open
Main.javaand edit thefoldersToWatchlist to point to your specific directories:foldersToWatch.add(Paths.get("C:\\Users\\You\\Downloads")); foldersToWatch.add(Paths.get("D:\\Work\\Files"));
- Run
Main.java. The console will show:--- π§Ή Starting Initial Cleanup --- β Moved: vacation.jpg (in Downloads) --- π Watchdog is watching 2 folders ---
To run this in the background without an IDE:
- Build the artifact in IntelliJ (Project Structure -> Artifacts).
- Run via command line:
java -jar DownloadsWatchdog.jar
- (Optional) Add the JAR shortcut to your Windows Startup folder to run on boot.
Feel free to fork this project and add support for:
- A configuration file (JSON/Properties) to avoid hardcoding paths.
- A GUI system tray icon to pause/resume the watchdog.
This project is open-source and available under the MIT License.