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
+7.6k Javascript : How to check a browser's Do Not Track status?
+16.1k Golang : Test floating point numbers not-a-number and infinite example
+9.7k Golang : Translate language with language package example
+7.9k Golang : HTTP Server Example
+19.6k Golang : Determine if directory is empty with os.File.Readdir() function
+8.8k Golang : Capture text return from exec function example
+18.6k Golang : How to make function callback or pass value from function as parameter?
+9.7k CodeIgniter : Load different view for mobile devices
+7.9k Golang : Tell color name with OpenCV example
+22.2k Generate checksum for a file in Go
+11.1k Golang : Byte format example