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
+14.8k Golang : Send email with attachment(RFC2822) using Gmail API example
+16.2k Golang : How to check if input from os.Args is integer?
+34.1k Golang : Proper way to set function argument default value
+15k Golang : Basic authentication with .htpasswd file
+7.8k Golang : Generate human readable password
+14.6k Golang : How to get URL port?
+12.2k Golang : Detect user location with HTML5 geo-location
+11.7k Golang : Simple file scaning and remove virus example
+14.4k Golang : Simple word wrap or line breaking example
+14.3k Golang : Fix image: unknown format error
+9.1k Golang : Get SPF and DMARC from email headers to fight spam
+7k Golang : Levenshtein distance example