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
+10.4k Golang : Exit, terminating or aborting a program
+4.7k Golang : How to setup a disk space used monitoring service with Telegram bot
+26.4k Golang : Get and Set User-Agent examples
+14.5k Golang : Display list of time zones with GMT
+5.4k Golang : constant 20013 overflows byte error message
+10.2k Golang : 2 dimensional array example
+23.3k PHP : Convert(cast) string to bigInt
+13.7k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+11k Golang : Set image canvas or background to transparent
+11k Golang : Read XML elements data with xml.CharData example
+6.7k Golang : Intercept and compare HTTP response code example
+13.7k Golang : convert string or integer to big.Int type