photoprism/pkg/fs/name.go
Michael Mayer e796d036c2 Fix indexer and add sort by file name #328
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-05-22 19:05:16 +02:00

26 lines
595 B
Go

package fs
import (
"os"
"strings"
)
// RelativeName returns the file name relative to directory.
func RelativeName(fileName, directory string) string {
if fileName == directory {
return ""
}
if index := strings.Index(fileName, directory); index == 0 {
if index := strings.LastIndex(directory, string(os.PathSeparator)); index == len(directory)-1 {
pos := len(directory)
return fileName[pos:]
} else if index := strings.LastIndex(directory, string(os.PathSeparator)); index != len(directory) {
pos := len(directory) + 1
return fileName[pos:]
}
}
return fileName
}