aliyunpan/internal/syncdrive/sync_db_util.go

24 lines
447 B
Go
Raw Normal View History

2022-05-07 15:03:23 +08:00
package syncdrive
import (
"path"
"regexp"
"strings"
)
// FormatFilePath 格式化文件路径
func FormatFilePath(filePath string) string {
if filePath == "" {
return ""
}
// 是否是windows路径
2022-08-09 19:27:46 +08:00
matched, _ := regexp.MatchString("^([a-zA-Z]:)", filePath)
2022-05-07 15:03:23 +08:00
if matched {
// 去掉卷标签例如D:
filePath = string([]rune(filePath)[2:])
}
filePath = strings.ReplaceAll(filePath, "\\", "/")
return path.Clean(filePath)
}