github.com/enetx/g@v1.0.80/examples/files/files.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/enetx/g" 7 ) 8 9 func main() { 10 f := g.NewFile("some/dir/that/dont/exist/file.txt") 11 12 f.Append("one").Unwrap().Append("\n") 13 f.Append("two").Ok().Append("\n") 14 15 f.Close() 16 17 f.Read().Unwrap().Print() 18 19 stat := f.Stat().Unwrap() 20 fmt.Printf("Name(): %v\n", f.Name()) 21 fmt.Printf("IsDir(): %v\n", f.IsDir()) 22 fmt.Printf("f.IsLink(): %v\n", f.IsLink()) 23 fmt.Printf("Size(): %v\n", stat.Size()) 24 fmt.Printf("Mode(): %v\n", stat.Mode()) 25 fmt.Printf("ModeTime(): %v\n", stat.ModTime()) 26 27 fmt.Println(f.Exist()) 28 f.Dir().Unwrap().Path().Unwrap().Print() 29 f.Path().Unwrap().Print() 30 31 f = f.Rename("aaa/aaa/aaa/fff.txt").Ok().Copy(f.Dir().Ok().Join("copy_of_aaa.txt").Ok()).Ok() 32 f.Name().Print() 33 34 f.Ext().Print() 35 f.MimeType().Unwrap().Print() 36 37 fmt.Println("--------------------------------------------------------------") 38 39 f.Path().Unwrap().Print() 40 41 dir, file := f.Split() 42 fmt.Println(dir.Path().Unwrap(), file.Name()) 43 44 newFile := g.NewFile(dir.Join(file.Name()).Ok()) 45 newFile.Path().Ok().Print() 46 }