fix path format error

This commit is contained in:
xiaoyaofenfen 2022-08-09 19:27:46 +08:00
parent ac5eb94305
commit d90894898f
2 changed files with 6 additions and 2 deletions

View File

@ -13,7 +13,7 @@ func FormatFilePath(filePath string) string {
}
// 是否是windows路径
matched, _ := regexp.MatchString("^[a-zA-Z]:*", filePath)
matched, _ := regexp.MatchString("^([a-zA-Z]:)", filePath)
if matched {
// 去掉卷标签例如D:
filePath = string([]rune(filePath)[2:])

View File

@ -6,5 +6,9 @@ import (
)
func TestFormatFilePath(t *testing.T) {
fmt.Println(FormatFilePath("D:/-beyond/p/9168473.html"))
fmt.Println(FormatFilePath("D:\\-beyond\\p\\9168473.html"))
}
func TestFormatFilePath2(t *testing.T) {
fmt.Println(FormatFilePath("/my/folder/test.txt"))
}