diff --git a/pkg/io/files/file_exists_checker.go b/pkg/io/files/file_exists_checker.go index 1629370..4f7a131 100644 --- a/pkg/io/files/file_exists_checker.go +++ b/pkg/io/files/file_exists_checker.go @@ -2,7 +2,9 @@ package files import ( "errors" + "fmt" "os" + "path/filepath" ) func IsFileExists(fileLocation string) bool { @@ -12,3 +14,19 @@ func IsFileExists(fileLocation string) bool { 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 +}