github.com/gogf/gf/v2@v2.7.4/os/gfile/gfile_z_example_search_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package gfile_test
     8  
     9  import (
    10  	"fmt"
    11  
    12  	"github.com/gogf/gf/v2/os/gfile"
    13  )
    14  
    15  func ExampleSearch() {
    16  	// init
    17  	var (
    18  		fileName = "gfile_example.txt"
    19  		tempDir  = gfile.Temp("gfile_example_search")
    20  		tempFile = gfile.Join(tempDir, fileName)
    21  	)
    22  
    23  	// write contents
    24  	gfile.PutContents(tempFile, "goframe example content")
    25  
    26  	// search file
    27  	realPath, _ := gfile.Search(fileName, tempDir)
    28  	fmt.Println(gfile.Basename(realPath))
    29  
    30  	// Output:
    31  	// gfile_example.txt
    32  }