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
+6k Golang : Measure execution time for a function
+20.6k Golang : Read directory content with os.Open
+22.1k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+23.9k Golang : Call function from another package
+13.5k Golang : Get user input until a command or receive a word to stop
+24k Golang : Find biggest/largest number in array
+15.5k Golang : ROT47 (Caesar cipher by 47 characters) example
+13.1k Golang : How to get a user home directory path?
+6.3k Unix/Linux : Use netstat to find out IP addresses served by your website server
+26k Mac/Linux and Golang : Fix bind: address already in use error
+7.4k Golang : Rot13 and Rot5 algorithms example