一、dirname
// 只针对路径字符串中含有/的
func getaDirName(str string) string {
if strings.HasSuffix(str,"/") {
newDir := str[:len(str)-1]
fmt.Println(newDir)
return newDir
} else {
dirSlice := strings.Split(str,"/")
newDirSlice := dirSlice[:len(dirSlice)-1]
newDir := strings.Join(newDirSlice,"/")
fmt.Println(newDir)
return newDir
}
}
二、basename
func getFileName(path string) string {
filename := strings.Split(path,"/")[len(strings.Split(path,"/"))-1]
return filename
}