Ainar-G Asked:2020-01-17 22:47:07 +0800 CST2020-01-17 22:47:07 +0800 CST 2020-01-17 22:47:07 +0800 CST 如何将路径拆分为基本文件名和路径? 772 ( 来自ENSO的问题的翻译。) 如何将路径拆分为基本文件名和Go中的路径?也就是说,"/some/path/to/remove/file.name"如果我想得到 "/some/path/to/remove/"和"file.name". golang 1 个回答 Voted Best Answer Ainar-G 2020-01-17T22:47:07+08:002020-01-17T22:47:07+08:00 ( ENSO 的答案翻译。) 借助函数 filepath.Base 和 filepath.Dir: const path = "/some/path/to/remove/file.name" fmt.Println(filepath.Base(path)) fmt.Println(filepath.Dir(path)) // Output: // // file.name // /some/path/to/remove 游乐场: https: //play.golang.org/p/V9-mpXib1EZ。
( ENSO 的答案翻译。)
借助函数
filepath.Base
和filepath.Dir
:游乐场: https: //play.golang.org/p/V9-mpXib1EZ。