FileSorter is a small C++17 command-line utility that sorts files by their extensions using a user-defined configuration file.
The program reads extension rules from a text config, shows a preview of where each file will be moved, asks for confirmation, and then moves files from a source folder into categorized folders inside an output folder.
- Reads sorting rules from a
.txtconfig file - Supports multiple extensions per category
- Ignores empty lines and comments in the config
- Trims extra spaces around folder names and extensions
- Shows a safe preview before moving files
- Moves files into category folders
- Sends unknown extensions to
Other - Lets the user choose:
- source folder
- output folder
- Keeps the console open after execution when launched as an
.exe
Source folder:
input/
movie.mp4
archive.zip
setup.exe
notes.txt
unknown.qwe
Config:
Video: .mp4, .avi, .mkv
Archives: .zip, .rar, .7z
Programs: .exe, .msi
Documents: .txt, .pdf, .docx
Output folder after sorting:
sorted/
Video/
movie.mp4
Archives/
archive.zip
Programs/
setup.exe
Documents/
notes.txt
Other/
unknown.qwe
FileSorter/
src/
main.cpp
config_parser.cpp
config_parser.h
file_sorter.cpp
file_sorter.h
config/
File_Exp.txt
The configuration file describes which extensions should go into which folders.
Example:
# Media files
Video: .mp4, .avi, .mkv
Images: .png, .jpg, .jpeg, .webp
# Documents
Documents: .txt, .pdf, .docx
# Archives
Archives: .zip, .rar, .7z
# Programs
Programs: .exe, .msi
Rules:
- One category per line
- Folder name goes before
: - Extensions go after
: - Extensions are separated by commas
- Spaces around names and extensions are allowed
- Empty lines are ignored
- Lines starting with
#are treated as comments
- The program loads extension rules from
config/File_Exp.txt. - The user enters a source folder.
- The user enters an output folder.
- The program scans files in the source folder.
- For each file, it checks the file extension.
- If the extension exists in the config, the file is assigned to the matching category.
- If the extension is unknown, the file is assigned to
Other. - The program shows a preview.
- After confirmation, files are moved into the output folder.
From the project root:
cd src
g++ main.cpp config_parser.cpp file_sorter.cpp -std=c++17 -o sorterRun:
sorter.exeFrom the project root:
cd src
g++ main.cpp config_parser.cpp file_sorter.cpp -std=c++17 -o sorterRun:
sorter- Build the project.
- Make sure the config file exists:
config/File_Exp.txt
- Run the program.
- Enter the source folder path.
- Enter the output folder path.
- Check the preview.
- Confirm sorting with
y.
Example:
Enter source folder:
C:\Users\User\Desktop\input
Enter output folder:
C:\Users\User\Desktop\sorted
=== Preview ===
movie.mp4 -> C:\Users\User\Desktop\sorted\Video\movie.mp4
archive.zip -> C:\Users\User\Desktop\sorted\Archives\archive.zip
Continue moving files? (y/n):
y
Use a test folder before running the program on important files.
The program moves files, so the original source folder will no longer contain the moved files after confirmation.
Recommended first test:
test_input/
video.mp4
archive.zip
document.txt
unknown.qwe
- Does not sort files recursively (partially finished)
- Does not rename files if a file with the same name already exists
- Does not currently support undo
- Does not copy files, only moves them
- Extension matching depends on how extensions are written in the config
- Recursive folder sorting (partially finished)
- Dry-run mode as a command-line option
- Copy mode instead of move mode
- Automatic conflict renaming, for example
file_1.txt - Logging to a file
- JSON or TOML config support
- GUI version
- CMake build support
This project is a small practical utility for organizing files automatically.
It is also a learning project focused on:
- C++17
std::filesystem- file handling
- config parsing
- maps and strings
- modular project structure
- safe command-line workflows