An application that recursively reads files from a source directory and copies them to a destination directory organized by year and month based on the file's modification time. Mainly to organize my photos, but can work on any type of files.
- Recursively processes all files in the source directory and its subdirectories
- Organizes files by year and month (YYYY/YYYY-MM-DD format)
- Multiple file conflict resolution strategies: skip, overwrite, or rename
- Preserves file permissions
- Provides clear error messages and validation
- Shows progress during file copying
./snaparchive [options] <source_folder> <dest_folder>source_folder: The path to the directory containing files to organizedest_folder: The path where organized files will be copied
-overwrite <mode>: Behavior when file exists (default: "skip")skip: Skip files that already exist in destination (default)overwrite: Replace existing files with source filesrename: Create new file with incremented number suffix
./snaparchive ./photos ./organized_photos./snaparchive -overwrite overwrite ./photos ./organized_photos./snaparchive -overwrite rename ./photos ./organized_photosThis will copy all files from ./photos (and its subdirectories) to ./organized_photos, organizing them in a structure like:
organized_photos/
├── 2023/
│ ├── 2023-01-06/
│ │ ├── photo1.jpg
│ │ └── document1.jpg
│ └── 2023-12-06/
│ └── photo2.jpg
└── 2024/
└── 2024-12-24/
└── christmas.cr3
brew tap medalhas/tools
brew install snaparchiveTo build the application:
go build -o snaparchive main.goFiles are organized based on their modification time into directories following the pattern:
YYYY/YYYY-MM-DD/filename- Example:
2025/2025-10-05/myfile.txt
The application provides three strategies for handling file conflicts:
- Skip (default): Skip files that already exist in the destination
- Overwrite: Replace existing files with source files
- Rename: Append a number to make the filename unique (
myfile.txt→myfile_1.txt→myfile_2.txt, etc.)
The application includes comprehensive error handling for:
- Invalid command line arguments
- Non-existent source directories
- Permission issues
- File copy failures
- Go 1.16 or later
- Read access to source directory
- Write access to destination directory (or parent directory to create it)