14c89022d3
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
25 lines
541 B
Go
25 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
|
|
}
|