golang學(xué)習(xí)筆記(13)
2111
發(fā)布于 云南 2022-08-05 · 1.1w瀏覽 1回復(fù) 3贊

發(fā)現(xiàn)關(guān)于文件路徑有兩個庫:path和path/filepath,測試了一下發(fā)現(xiàn)path無法識別windows路徑(比如:c:\\user\\desktop),path/filepath則可以同時識別linux'和windows路徑。

上代碼:


func main() {

? ? f1 := "d:\\test\\test.go"

? ? p1 := path.Dir(f1)

? ? fp1 := filepath.Dir(f1)

? ? fmt.Println("path:", p1)

? ? fmt.Println("filepath", fp1)

?

? ? f2 := "/root/test/test.go"

? ? p2 := path.Dir(f2)

? ? fp2 := filepath.Dir(f2)

? ? fmt.Println("path:", p2)

? ? fmt.Println("filepath", fp2)

}


執(zhí)行結(jié)果:

path: .
filepath d:\work\test
path: /root/test
filepath \root\test

2111
~
瀏覽 1.1w
3 收藏 1
相關(guān)推薦
最新評論 1
贊過的人 3
評論加載中...

暫無評論,快來評論吧!