DEV Community

Cover image for Building an Efficient File Organizer with Rust
Joel Jaison
Joel Jaison

Posted on

Building an Efficient File Organizer with Rust

Managing a cluttered Downloads folder is a problem that many of us face. Files pile up quickly, and before we know it, important documents, images, and videos get lost in a sea of irrelevant or outdated downloads. With this in mind, I set out to build a tool that organizes files automatically while being lightweight and efficient. Hereโ€™s the journey of how I developed the Download Manager, the challenges I encountered, and the lessons I learned along the way.

What is Download Manager?

The Download Manager is a Rust-based application that I built to automatically organize the Downloads folder. It monitors new file events, waits for files to stabilize, and categorizes them into folders like Images, Videos, Documents, Archives, Audio, and Others. The tool is built for Windows and is designed to be both fast and resource-efficient.

How to Use Download Manager

1. Download the Executable

Visit the GitHub releases page and download the prebuilt executable file (downloadManager.exe).

2. Configure in Task Scheduler

To ensure the tool runs automatically at system startup:

  1. Open Task Scheduler (Press Win + R, type taskschd.msc, and press Enter).
  2. Click Create Task on the right-hand side.
  3. In the General tab:
    • Name the task (e.g., "Download Organizer").
    • Select Run whether user is logged on or not.
    • Check Run with highest privileges.
  4. Go to the Triggers tab:
    • Click New and set the trigger to At system startup.
    • Click OK.
  5. Go to the Actions tab:
    • Click New.
    • Set Action to Start a program.
    • Browse to the downloaded downloadManager.exe file and select it.
    • Click OK.
  6. Go to the Conditions tab:
    • Uncheck Start the task only if the computer is on AC power.
    • Check Wake the computer to run this task.
  7. Click OK to save the task.

The tool will now run automatically at startup and monitor your Downloads folder.

3. Running Manually

If you prefer to run the program manually, simply double-click the downloadManager.exe file. The tool will start monitoring the Downloads folder immediately.

Problems I Faced and How I Solved Them

1. Handling Temporary Files

Problem: Many browsers like Chrome create .tmp or .crdownload files while downloading. If my tool processed these files prematurely, it interrupted downloads.

Solution: I implemented a file stability mechanism. The program ignores .tmp and .crdownload files until they are renamed. Additionally, I periodically check file size to ensure the file is stable before moving it.

2. Monitoring Resource Usage

Problem: File monitoring could easily become resource-intensive, consuming significant CPU and memory, especially during frequent file events.

Solution: To address this, I:

  • Used Rust's efficient libraries like notify for file event monitoring.
  • Implemented benchmarks to analyze and optimize CPU and memory usage. The program stabilizes at ~13 MB of memory usage and spikes to ~0.77% CPU during active monitoring, making it suitable for everyday use.

Fun Fact: Did you know that Rust is often called a "memory-safe language" because it avoids common memory errors like null pointer dereferences and buffer overflows?

3. Ensuring Cross-File Compatibility

Problem: Files come in a variety of formats. I needed to ensure proper categorization for dozens of extensions.

Solution: I implemented an extensive list of file extensions, mapping them to their respective categories like Images, Videos, and Documents. For unknown extensions, I used a default "Others" folder. This keeps the system future-proof for new file types.

4. Avoiding Interruptions During System Startup

Problem: Running the tool via Task Scheduler sometimes caused a terminal window to appear, disrupting the user experience.

Solution: I recompiled the program using the windows_subsystem = "windows" flag in Rust, ensuring the tool runs silently in the background without a visible terminal window.

5. Keeping It User-Friendly

Problem: Many users are not comfortable with command-line tools or complex setups.

Solution: I:

  • Provided a prebuilt executable for direct download from GitHub releases.
  • Included detailed instructions for configuring the tool in Task Scheduler for automatic startup.
  • Added desktop notifications to inform users of file movements, making the experience interactive and transparent.

Benchmarking and Testing

I tested the Download Manager on the following device:

  • Device Name: Lenovo Ideapad Gamming 3i
  • Processor: 12th Gen Intel(R) Core(TM) i5-12450H @ 2.00 GHz
  • Installed RAM: 32.0 GB
  • OS: Windows 11 Home, Version 23H2

Benchmark Results:

  • CPU Usage: Peaks at ~0.77% during active file monitoring.
  • Memory Usage: Stabilizes at ~13 MB during regular operations.

Insights:

  • The tool runs efficiently in the background and is ideal for users who want a "set it and forget it" solution. I made sure it remains user-friendly and lightweight.
  • Resource usage remains minimal even during heavy file operations, thanks to Rust's performance and low-level control.

Ideas for Similar Projects

If you're inspired by this project, here are some ideas you can explore yourself:

  1. Photo Organizer:
  • Automatically sort photos by date, location (using EXIF data), or event name.
  1. Music Library Manager:
  • Categorize audio files based on artist, album, or genre.
  1. Document Digitizer:
  • Monitor scanned documents and automatically rename and move them based on OCR-detected content.
  1. Video Compressor:
  • Monitor video folders and compress large files automatically to save disk space.
  1. Cross-Platform File Organizer:
  • Extend the file organizer concept to support Linux and macOS.

Final Thoughts

The Download Manager project was both a challenging and rewarding experience. It taught me the importance of handling edge cases like temporary files and optimizing for low resource usage. Most importantly, it reinforced the power of automation to make life simpler and more productive.

I hope this tool helps you keep your Downloads folder tidy. I'd love to hear your feedback and ideas! If youโ€™d like to contribute or suggest features, check out our GitHub repository!

GitHub logo Joeljaison391 / Downloads-Organizer

A Rust application designed to automate the organization of your downloads. It watches for new files and moves them to appropriate directories based on their extension, simplifying file management and improving workflow.

Download Manager

Overview

A lightweight Rust-based file monitoring and organizing tool designed to automatically segregate files downloaded into appropriate folders based on their type. The program monitors the Downloads folder for file events and organizes files into categories like Images, Videos, Documents, Archives, Audio, and Others.

Features

  • Monitors the Downloads folder for new files.
  • Ignores temporary and partially downloaded files (e.g., .tmp, .crdownload).
  • Waits for file stability before processing.
  • Categorizes files into appropriate subfolders.
  • Sends desktop notifications upon successful file organization.
  • Logs errors and processing details for debugging.
  • Efficient resource usage.

Supported File Types

Categories:

  1. Images
    • .jpg, .png, .gif, .bmp, .tiff, .svg, .webp
  2. Videos:
    • .mp4, .mkv, .avi, .mov, .flv, .wmv, .webm, .mpeg
  3. Documents:
    • .pdf, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .txt, .csv
  4. Archives
    • โ€ฆ

Feel free to leave your comments or suggestions below. Happy coding!

Top comments (3)

Collapse
 
kichuman28 profile image
Adwaith Jayasankar

I will be using this one..my download folder is a message ๐Ÿ˜ญ

Collapse
 
rockiesmagicnum profile image
Andrew Martin

I have a similar project that has been on my back burner for months now, but I had the same idea, the difference being it's meant to consolidate flash drives that have been used to archive various media over the years, and now nobody knows if those files have been backed up formally somewhere, if there are duplicate backups, any of those things.

I have a lot of experience using the system.io library in C# and I've been using json files to keep a manifest of what has been processed to help mitigate duplicates and further storage thereof.

This is cool, I have been debating starting the whole thing over in a cross-platform compilible language like rust or go. Maybe I should at least finish the one that I have. ๐Ÿ˜†

Collapse
 
adesoji1 profile image
Adesoji1

I noticed you didn't have a docker file, could I add it