feature: added GetFirstIndexedNonExistingFilePath to files

master
amorozov 2024-06-25 15:45:57 +03:00
parent b5430036f9
commit 18f289fe90
1 changed files with 18 additions and 0 deletions

View File

@ -2,7 +2,9 @@ package files
import ( import (
"errors" "errors"
"fmt"
"os" "os"
"path/filepath"
) )
func IsFileExists(fileLocation string) bool { func IsFileExists(fileLocation string) bool {
@ -12,3 +14,19 @@ func IsFileExists(fileLocation string) bool {
return true 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
}