33 lines
537 B
Go
33 lines
537 B
Go
package files
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func IsFileExists(fileLocation string) bool {
|
|
if _, err := os.Stat(fileLocation); errors.Is(err, os.ErrNotExist) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
func GetFirstIndexedNonExistingFilePath(parentDir string, fileBaseName string) string {
|
|
filePath := filepath.Join(parentDir, fileBaseName)
|
|
index := 0
|
|
for {
|
|
if !IsFileExists(filePath) {
|
|
break
|
|
}
|
|
|
|
index++
|
|
|
|
filePath = filepath.Join(parentDir, fmt.Sprintf("%s-%d", fileBaseName, index))
|
|
}
|
|
|
|
return filePath
|
|
}
|