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

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/enetx/g"
     7  )
     8  
     9  func main() {
    10  	// Create a directory instance for the current directory and print its path
    11  	d := g.NewDir("")
    12  	d.Path().Unwrap().Print()
    13  
    14  	// Check if the directory exists
    15  	fmt.Println(d.Exist())
    16  
    17  	// Create all directories in the specified path, even if some of the intermediate directories don't exist
    18  	g.NewDir("./some/dir/that/dont/exist/").CreateAll().Unwrap()
    19  
    20  	// Rename the directory "./some/dir/that/" to "./some/dir/aaa/ccc/" and print the new path
    21  	g.NewDir("./some/dir/that/").Rename("./some/dir/aaa/ccc/").Unwrap().Print()
    22  
    23  	// Create all directories in the path "aaa", then rename it to "bbb" and print the new path
    24  	g.NewDir("aaa").CreateAll().Unwrap().Rename("bbb").Unwrap()
    25  
    26  	// Create a temporary directory, print its path, and assign it to variable 'd'
    27  	d = g.NewDir("").CreateTemp().Unwrap().Print()
    28  
    29  	// Remove the directory and print whether it exists after removal
    30  	d.Remove().Unwrap()
    31  	fmt.Println(d.Exist())
    32  }