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.8k Golang : Underscore string example
+5.9k Golang : Find change in a combination of coins example
+6k Golang : Generate multiplication table from an integer example
+11.6k Swift : Convert (cast) Float to String
+17.8k Golang : [json: cannot unmarshal object into Go value of type]
+7k Nginx : Password protect a directory/folder
+16.5k Golang : Test floating point numbers not-a-number and infinite example
+7.2k Golang : Transform lisp or spinal case to Pascal case example
+8.7k Golang : Another camera capture GUI application with GTK and OpenCV
+5.8k Golang : Detect words using using consecutive letters in a given string
+12.9k Golang : Convert int(year) to time.Time type
+14.7k Golang : Convert(cast) int to float example