A small C++ utility that watches a configured directory and sorts files into subfolders (by extension). Builds with CMake and uses nlohmann/json and efsw (file-system watcher).
- Scans a target directory and sorts files into subfolders by extension.
- Watches the directory for changes and continues running to sort new files as they appear.
- Uses a JSON config stored in the user's home config folder.
- A C++ compiler with C++17 support (e.g.,
g++,clang++). - CMake ≥ 3.30. The project uses CMake and FetchContent to obtain dependencies.
- Network access during build (used by CMake FetchContent to download dependencies).
On Debian/Ubuntu you can prepare a build environment with (example):
sudo apt update
sudo apt install build-essential cmake git(If you use another distro, install equivalent packages and a modern compiler.)
Run these commands from the project root:
# clone (if you haven't)
git clone https://gitlab.com/Chebo7/file-sorter.git
cd file-sorter
# out-of-source build
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17
cmake --build . --config ReleaseAfter a successful build the executable FileSorter will be created in build/ (executable name defined in CMakeLists.txt).
FileSorter reads its config from:
~/.config/fsortrc.json
# (equivalent path: $HOME/.config/fsortrc.json)
This path is hard-coded in the config parser of the project. If the file does not exist the program will attempt to create a default config and instruct you to edit it.
Create or edit ~/.config/fsortrc.json with the directory you want to watch:
{
"directory": "/home/username/Downloads"
}Notes:
- The value must be a valid absolute path to a directory the user can read/write.
- If the config is missing, FileSorter writes a default with
"change-it"and throws an instruction error asking you to configure it.
From the build directory (or copy the binary somewhere in your $PATH):
# run in foreground (useful for testing)
./FileSorterThe program performs an initial scan and sort, then enters a watch loop to keep sorting new files as they appear. (The main loop is blocking, so it runs continuously until stopped.)
To run it in background (quick & dirty):
nohup ./FileSorter &>/var/log/filesorter.log &Or better, create a systemd user service (recommended on systemd systems). Example unit file:
# ~/.config/systemd/user/filesorter.service
[Unit]
Description=FileSorter - watch & sort files
[Service]
ExecStart=/home/username/path/to/FileSorter
WorkingDirectory=/home/username
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.targetEnable & start (as the user):
systemctl --user daemon-reload
systemctl --user enable --now filesorter.service
journalctl --user -u filesorter.service -fReplace /home/username/path/to/FileSorter with the built binary path or installed location.
To install the binary system-wide (example):
sudo cp build/FileSorter /usr/local/bin/
# then run /usr/local/bin/FileSorter or create a systemd unit that points to it- Config creation error: If the program reports it created the default config and exits, open
~/.config/fsortrc.json, replace"change-it"with your target directory and re-run. - Permission errors: Ensure the user running FileSorter has read/write permission for the target directory and the config file.
- Build failures: Make sure CMake, a modern compiler, and development tools are installed. If your toolchain doesn’t support
<filesystem>(C++17), upgrade your compiler. - No files are moved: The sorter groups by extension; files without extension or files already in matching directories may not move. Check logs/console output for errors.
- Fork or create a merge request on the GitLab repository.
- Open issues for bugs or desired improvements.
- Prefer small, focused commits and provide clear descriptions.
This project is licensed under the MIT License. See LICENSE in the repository.