photoprism/pkg/fs/name.go
Michael Mayer fe28c7d284 Backend: Add support for .ppignore files #233 #287
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-05-03 14:40:59 +02:00

21 lines
551 B
Go

package fs
import (
"os"
"strings"
)
// RelativeName returns the file name relative to directory.
func RelativeName(fileName, directory string) string {
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
}