This is a lightweight Rust program designed to help you organize files in a directory by categorizing them into folders based on file extensions (e.g., images, documents, videos). It ensures files are moved to their appropriate folders without overwriting existing files by adding a unique identifier to files with the same name.
The program recursively scans the specified directory and organizes files into predefined folders according to their file extensions. If a file with the same name already exists in the target folder, the program appends a unique number to the filename to avoid any conflict.
The file extensions are mapped to folders through a configurable mapping within the file_folder_map
function. You can easily customize the mapping by modifying this function in the source code.
Out-of-the-box, the following file types are supported:
- Images:
jpeg
,jpg
,png
,HEIC
,gif
,svg
,webp
- Documents:
doc
,txt
,pdf
,xlsx
,docx
,csv
,docs
- Videos:
webm
,mp4
- JSON:
json
You can add support for additional file types by simply updating the file_folder_map
in the code.
To run this program, you need:
- Rust installed on your machine.
-
Open a terminal and run the following commands to clone the repository and navigate to the project folder:
git clone https://github.com/your-username/file-organizer.git cd file-organizer
-
Run the program using Cargo, passing the directory you want to organize as an argument:
cargo run -- <directory-path>
Replace
<directory-path>
with the actual path to the folder you want to organize.For example:
cargo run -- C:/Users/admin/Downloads
This will organize the
Downloads
folder by sorting files into subfolders likeImages
,Documents
,Videos
, andJSON
.
You can easily customize the mapping of file extensions to folders by editing the map_file_to_folder()
function in the source code. To add support for a new file type, just insert a new line like this:
file_folder_map.insert("pdf", "Documents");
This will move all .pdf
files into the Documents
folder.
- File organization by extension: Automatically organizes files into predefined folders based on their extensions.
- Conflict handling: If a file with the same name exists in the target folder, the program appends a unique identifier to the new file's name to prevent overwriting.
- Customizable mapping: Easily modify the folder mappings to support new file types or change the existing ones.
- Cross-platform: Works on Linux, macOS, and Windows.
Contributions are welcome! If you have suggestions for new features, optimizations, or bug fixes, feel free to open an issue or submit a pull request.