autonamer

package module
v0.0.0-...-5c643ce Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2019 License: MIT Imports: 5 Imported by: 0

README

Build Status contributions welcome codecov GoDoc

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).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pick

func Pick(tries int, path string) (newPath string, err error)

Pick automatically increment the (n) of a filename if it exists, and will attempt n tries before failing with an error.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL