github.com/enetx/g@v1.0.80/examples/dirs/dirs_read.go (about)

     1  package main
     2  
     3  import "github.com/enetx/g"
     4  
     5  func main() {
     6  	// Iterate over and print the names of files in the current directory
     7  	g.NewDir(".").Read().Ok().Iter().ForEach(func(f *g.File) { f.Name().Print() })
     8  
     9  	// Iterate over and print the full paths of files in the current directory
    10  	g.NewDir(".").Read().Ok().Iter().ForEach(func(f *g.File) { f.Path().Ok().Print() })
    11  
    12  	// Iterate over and print the names of files in the current directory with a *.go extension
    13  	g.NewDir("*.go").Glob().Unwrap().Iter().ForEach(func(f *g.File) { f.Name().Print() })
    14  
    15  	// Iterate over and print the full paths of files in the current directory with a *.go extension
    16  	g.NewDir("*.go").Glob().Unwrap().Iter().ForEach(func(f *g.File) { f.Path().Ok().Print() })
    17  
    18  	// Iterate over and print the full paths of non-directory files in the current directory
    19  	g.NewDir(".").Read().Unwrap().Iter().ForEach(func(f *g.File) {
    20  		if !f.Stat().Unwrap().IsDir() {
    21  			f.Path().Unwrap().Print()
    22  		}
    23  	})
    24  }