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
+5.9k Mac OSX : Find large files by size
+14.2k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+20.4k Golang : Convert seconds to minutes and remainder seconds
+15.2k Golang : Convert slice to array
+2.6k Java : Get FX sentiment from website example
+10.6k Golang : Convert(cast) float to int
+22.9k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+4.9k Get website traffic ranking with Similar Web or Alexa
+11.1k Golang : Add ASCII art to command line application launching process
+7.1k Golang : Emulate NumPy way of creating matrix example
+17.1k Golang : Logging with logrus
+9.5k Golang : How to transmit update file to client by HTTP request example