feature: added GetFirstIndexedNonExistingFilePath to files
parent
b5430036f9
commit
18f289fe90
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue