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
+33.9k Golang : Create x509 certificate, private and public keys
+4.2k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+6.1k Golang : Calculate US Dollar Index (DXY)
+38.9k Golang : How to iterate over a []string(array)
+11.5k SSL : The certificate is not trusted because no issuer chain was provided
+11.4k Golang : Find age or leap age from date of birth example
+5k Golang : Issue HTTP commands to server and port example
+9.5k Golang : Copy map(hash table) example
+11.4k Swift : Convert (cast) Float to String
+23.9k Golang : Upload to S3 with official aws-sdk-go package
+17.9k Golang : Convert IPv4 address to decimal number(base 10) or integer
+12.1k Golang : Flush and close file created by os.Create and bufio.NewWriter example