Categories: GoFrame 教程

GoFrame gfile-文件检索

文件检索

Search

  • 说明:在指定目录(默认包含当前目录、运行目录、主函数目录;不会递归子目录)中搜索文件并返回真实路径。
  • 格式:
func Search(name string, prioritySearchPaths ...string) (realPath string, err error) 
  • 示例:
func ExampleSearch() {
 // init
 var (
  fileName = "gflie_example.txt"
  tempDir  = gfile.TempDir("gfile_example_search")
  tempFile = gfile.Join(tempDir, fileName)
 )

 // write contents
 gfile.PutContents(tempFile, "goframe example content")

 // search file
 realPath, _ := gfile.Search(fileName, tempDir)
 fmt.Println(gfile.Basename(realPath))

 // Output:
 // gflie_example.txt
}

冒牌SEO

前端开发者,欢迎大家一起沟通和交流。

Share
Published by
冒牌SEO

Recent Posts

聊聊vue3中的defineProps

在Vue 3中,defineP…

1 周 ago

在 Chrome 中删除、允许和管理 Cookie

您可以选择删除现有 Cooki…

2 周 ago

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

3 周 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

4 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

1 月 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

1 月 ago