September 2017
Intermediate to advanced
466 pages
9h 33m
English
In this section, we will illustrate how to delete files and directories using the os.Remove() Go function.
The rm.go file is a Go implementation of the rm(1) tool that illustrates how you can delete files in Go. Although the core functionality of rm(1) is there, the options of rm(1) are missing: it would be a good exercise to try to implement some of them. Just pay extra attention when implementing the -f and -R options.
The Go code of rm.go is as follows:
package main import ( "fmt" "os" ) func main() { arguments := os.Args if len(arguments) == 1 { fmt.Println("Please provide an argument!") os.Exit(1) } file := arguments[1] err ...Read now
Unlock full access