mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-02-13 22:19:04 +08:00
24 lines
446 B
Go
24 lines
446 B
Go
|
package syncdrive
|
|||
|
|
|||
|
import (
|
|||
|
"path"
|
|||
|
"regexp"
|
|||
|
"strings"
|
|||
|
)
|
|||
|
|
|||
|
// FormatFilePath 格式化文件路径
|
|||
|
func FormatFilePath(filePath string) string {
|
|||
|
if filePath == "" {
|
|||
|
return ""
|
|||
|
}
|
|||
|
|
|||
|
// 是否是windows路径
|
|||
|
matched, _ := regexp.MatchString("^[a-zA-Z]:*", filePath)
|
|||
|
if matched {
|
|||
|
// 去掉卷标签,例如:D:
|
|||
|
filePath = string([]rune(filePath)[2:])
|
|||
|
}
|
|||
|
filePath = strings.ReplaceAll(filePath, "\\", "/")
|
|||
|
return path.Clean(filePath)
|
|||
|
}
|