­

go:文件路径相关

  • 2019 年 11 月 22 日
  • 筆記

获取文件名:

filepath.Base("http://haha/asdfv.pdf")  # asdfv.pdf

获取后缀:

ext := filepath.Ext("http://haha/asdfv.pdf")  # .pdf

获取目录

filepath.Dir("/haha/asdfv.pdf")  # /haha

文件是否存在

func Exists(path string) bool {      _, err := os.Stat(path)    //os.Stat获取文件信息      if err != nil {          if os.IsExist(err) {              return true          }          return false      }      return true  }