A command-line tool written in C++ for organizing files in a directory based on their metadata (creation, modification, or access time) and size. This program allows you to move files into subdirectories categorized by the date of creation/last modification/access time and file size (small, medium, or large).
- Organize by file time: Organize files based on their creation, last modification, or last access time.
- Size categorization: Files are categorized into "small", "medium", and "large" based on their size.
- Dry-run mode: Preview the actions without actually moving any files.
- Verbose output: Provides detailed logs of the operations performed.
- Metadata-based directory structure: Moves files into directories based on a combination of their file extension and metadata (time & size).
- C++17 or later
- Meson build system (for build configuration)
- Linux-based system with
statx
support (Linux 4.11+)
To compile the program using Meson, follow these steps:
- On Ubuntu/Debian:
sudo apt install meson ninja-build
- On Arch Linux:
sudo pacman -S meson ninja
- On macOS (using Homebrew):
brew install meson ninja
-
Clone or copy the project to your local machine.
-
Navigate to the project directory:
cd /path/to/file_organizer
- Create a build directory and configure the project with Meson:
meson setup build
- Build the project using Ninja:
ninja -C build
To install the program on your system:
sudo ninja -C build install
This will place the executable in the system path, allowing you to run file_organizer
from anywhere.
./file_organizer [OPTIONS] <source_directory>
-h, --help
: Show help message and exit.-v, --verbose
: Enable verbose output (shows detailed information about each operation).-d, --dry-run
: Perform a trial run without making any actual changes.-t, --time [creation|modification|access]
: Specify the time attribute to organize by. Default iscreation
.--small <size_in_MB>
: Set the size threshold for "small" files (default: 1 MB).--medium <size_in_MB>
: Set the size threshold for "medium" files (default: 10 MB).
-
Organize files by default (creation time):
./file_organizer -v /path/to/source
-
Organize files by modification time, with custom size thresholds and dry-run:
./file_organizer --dry-run --time modification --small 2 --medium 20 /path/to/source
-
Organize files by access time without verbose output:
./file_organizer --time access /path/to/source
-
Metadata Collection: The program collects all files recursively from the source directory and retrieves their metadata (size and time attributes).
-
File Categorization: Based on the file size and time attribute chosen by the user, the program categorizes the files into directories structured by:
- Year/Month/Day (based on creation, modification, or access date).
- File size (small, medium, or large).
-
File Movement: The program moves files into the appropriate directories. If files already exist in the target directory, it checks for file content differences to avoid overwriting.
-
Dry-run: In dry-run mode, no files are actually moved; instead, the program prints out what it would do without making changes.
-
Verbose Logging: When enabled, the program logs detailed information about every file processed and directory created.
Files are organized into directories like this:
<source_directory>/<file_extension>/<year>/<month>/<day>/<size_category>/<file_name>
For example, a file named example.txt
with the creation date of 2024-12-06
and a size of 5 MB would be moved into a directory structure like:
<source_directory>/txt/2024/12/06/medium/example.txt
- The program handles errors such as missing permissions, invalid directories, and failed file moves gracefully, providing clear error messages.
- It also checks for the existence of the target directory and handles file conflicts by renaming files if necessary.
Idk just use if if you want i guess. QUEM SOU EU PRA IMPEDIR NE