photoprism/pkg/fs/name.go
Michael Mayer 14c89022d3 Improve browsing by original file and folder name #260
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-05-31 14:42:41 +02:00

26 lines
541 B
Go

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