mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 14:32:14 +08:00
24 lines
447 B
Go
24 lines
447 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)
|
||
}
|