imagedumper_desktop.go
func availableFilename(prefix, postfix string) (string, error) {
	const datetimeFormat = "20060102030405"

	now := time.Now()
	name := fmt.Sprintf("%s%s%s", prefix, now.Format(datetimeFormat), postfix)
	for i := 1; ; i++ {
		if _, err := os.Stat(name); err != nil {
			if os.IsNotExist(err) {
				break
			}
			if !os.IsNotExist(err) {
				return "", err
			}
		}
		name = fmt.Sprintf("%s%s_%d%s", prefix, now.Format(datetimeFormat), i, postfix)
	}
	return name, nil
}
func availableFilename(prefix, postfix string) (string, error) {
	const datetimeFormat = "20060102030405"

	now := time.Now()
	name := fmt.Sprintf("%s%s%s", prefix, now.Format(datetimeFormat), postfix)
	for i := 1; ; i++ {
		if _, err := os.Stat(name); err != nil {
			if os.IsNotExist(err) {
				break
			}
			if !os.IsNotExist(err) {
				return "", err
			}
		}
		name = fmt.Sprintf("%s%s_%d%s", prefix, now.Format(datetimeFormat), i, postfix)
	}
	return name, nil
}
// availableFilename returns a filename that is valid as a new file or directory.