
Autonamer
A tiny Go package for auto-incrementing filenames. Supply autonamer.Pick with your desired filename.
If the filename is already taken, a new, auto-incremented name will be returned.
The package implements the filename (2).ext convention of file naming.
Usage
import (
"github.com/mochi-co/autonamer"
)
// Pick(maxMumberOfTries, preferredPath)
newPath, err := autonamer.Pick(1000, "path/to/my/desired/filename.txt")
If filename.txt exists in the path, filename (2).txt will be returned instead. If (2) already exists, (3) will be tried, and so on, until the maximum number of tries is reached. If no viable filename is available, Pick will return with a max tries exceeded error.
Notes
- The incrementing starts at (2).