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
+11.2k Golang : Validate email address
+5.6k Golang : Humanize and Titleize functions
+17.2k Golang : Send email with attachment
+16.4k Convert JSON to CSV in Golang
+22.6k Golang : Upload to S3 with official aws-sdk-go package
+3.9k MariaDB/MySQL : Form select statement or search query with Chinese characters
+9.2k Golang : How to get quoted string into another string?
+7k Findstr command the Grep equivalent for Windows
+5.8k Golang : Output or print out JSON stream/encoded data
+6.2k Golang : Use modern ciphers only in secure connection
+3.9k Golang : Calculate a pip value and distance to target profit example
+12k Golang : Calculate elapsed years or months since a date