简体中文 | English
An intelligent media file organizer written in Go. This tool renames your photos and videos to a clean, consistent PREFIX_YYYYMMDD_HHMMSS.ext format based on their metadata. It's safe, fast, configurable, and cross-platform.
This project is a high-performance port and enhancement of an exceptionally well-written shell script.
- Intelligent Timestamping: Prioritizes authoritative metadata (EXIF/QuickTime) for renaming. If metadata is missing, it safely falls back to the file's last modification time (
mtime). - Metadata Enrichment: Intelligently fills in empty date/time tags within your media files (e.g.,
DateTimeOriginal,CreateDate) using the authoritative timestamp. It never overwrites existing valid data. - System Timestamp Sync: Synchronizes the file's system modification time to match the authoritative timestamp, ensuring consistency across your filesystem.
- Safety First:
- Automatic Backups: Creates a full
.tar.gzbackup of your target directory before making any changes. - Confirmation Prompt: Requires explicit user confirmation before starting, preventing accidental runs.
- Conflict Resolution: If two files have the exact same timestamp, it adds a random suffix
_[xxx]to avoid overwriting.
- Automatic Backups: Creates a full
- Dependency Awareness: Automatically detects if the
ExifTooldependency is missing and enters a safe, limited-functionality mode with clear warnings. - Highly Configurable: All key parameters (file prefixes, supported extensions, timezone) are managed in a simple
config.jsonfile. No need to edit the code. - Cross-Platform: Built with Go, it can be compiled to a single native executable for Linux, Windows, and macOS.
This tool relies on the excellent ExifTool to read and write media metadata. You must have it installed on your system.
- On Arch Linux:
sudo pacman -S perl-image-exiftool - On Debian/Ubuntu:
sudo apt-get install libimage-exiftool-perl - On macOS (with Homebrew):
brew install exiftool - On Windows: Download from the ExifTool website.
- Install
ExifTool(see above). - Go to the Releases Page of this repository.
- Download the appropriate binary for your operating system (e.g.,
media-sorter_linux_amd64). - Download the
config.jsonfile. - Place both the executable and
config.jsonin the same directory. - (For Linux/macOS) Make the binary executable:
chmod +x ./media-sorter_linux_amd64
Run the program from your terminal, pointing it to the directory you want to organize.
# Basic usage with the -dir flag
./media-sorter -dir /path/to/your/photos
# You can also use a positional argument
./media-sorter /path/to/your/photosCommand-line Flags:
| Flag | Description | Default |
|---|---|---|
-dir |
The target directory to process. (Required) | "" |
-depth |
Max depth for directory traversal. -1 for infinite (default). |
-1 |
-backup-dir |
Directory to store backups. | "./media_backups" |
-exiftool-path |
Manually specify the full path to the exiftool executable. | "" |
-no-backup |
Disable the default backup process. | false |
-yes |
Bypass the interactive confirmation prompt. | false |
-v, --version |
Show the application message. | false |
-h, --help |
Show this help message. | false |
You can customize the tool's behavior by editing the config.json file.
{
"image_prefix": "IMG",
"video_prefix": "VID",
"target_timezone": "+08:00",
"supported_image_extensions": [
"jpg", "jpeg", "png", "heic", "webp", "gif"
],
"supported_video_extensions": [
"mp4", "mov", "avi", "mkv"
]
}image_prefix/video_prefix: The text prepended to renamed image/video files.target_timezone: The timezone used when writing EXIF tags to images.supported_*_extensions: Case-insensitive lists of file types to process.
For Developers: Build from Source
- Install Go (version 1.18+).
- Clone the repository, and build the optimized binary:
# Clone the repository git clone https://github.com/Cornfy/media-sorter.git # navigate into the directory cd media-sorter # and build it go build -ldflags="-s -w" # or you can use the Makefile to build make help