From c38e3fa949b4191ef8e6bf36c8b652b499d58fd7 Mon Sep 17 00:00:00 2001 From: "rick.chan" Date: Wed, 14 Apr 2021 10:27:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Go=20filepath=20=E5=8C=85?= =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E4=BD=BF=E7=94=A8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rick.chan --- .../Go/Package/Path/Go_filepath_包基本使用.md | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Software/Development/Language/Go/Package/Path/Go_filepath_包基本使用.md diff --git a/Software/Development/Language/Go/Package/Path/Go_filepath_包基本使用.md b/Software/Development/Language/Go/Package/Path/Go_filepath_包基本使用.md new file mode 100644 index 0000000..c7a5570 --- /dev/null +++ b/Software/Development/Language/Go/Package/Path/Go_filepath_包基本使用.md @@ -0,0 +1,34 @@ +# Go filepath 包基本使用 + +```go +/** + * 返回所给路径的绝对路径 + * 输出绝对路径 F:\my\bin\log.txt + */ +path, _ := filepath.Abs("./log.txt") +fmt.Println(path) + +/** + * 返回所给路径的相对路径 + */ +filepath.Dir(path) + +/** + * 返回路径最后一个元素 + * 输出 log.txt + */ +fmt.Println(filepath.Base("./log.txt")) + +/** + * 返回路径中的扩展名 + * 输出 .jpg + */ +fmt.Println(filepath.Ext("./a/b/c/d.jpg")) + +/** + * 分割目录和文件 + * 输入出 C:/a/b/c/ d.jpg + */ +dir, file := filepath.Split("C:/a/b/c/d.jpg") +fmt.Println(dir, file) +```