Delete a directory in Go
A simple tutorial on how to delete a directory in Go. This tutorial is a respond to this solution which is not the recommended way.
removedir.go
package main
import (
"os"
)
func main() {
os.Remove("./TestDir")
}
To remove all the subdirectories under the target directory, replace os.Remove()
to os.RemoveAll()
Reference :
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+12.6k Golang : Exit, terminating or aborting a program
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+10.4k Golang : Generate random integer or float number
+15.3k Golang : Delete certain files in a directory
+5k Golang : Display packages names during compilation
+7.4k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+8.4k Golang : Convert word to its plural form example
+10.1k Golang : Bcrypting password
+13k Swift : Convert (cast) Int to String ?
+22.4k Golang : How to read JPG(JPEG), GIF and PNG files ?
+80.4k Golang : How to return HTTP status code?
+10.4k Golang : Meaning of omitempty in struct's field tag