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
+18.9k Golang : Implement getters and setters
+7k Mac OSX : Find large files by size
+15.7k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+15k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+15.4k Golang : How to get Unix file descriptor for console and file
+30k Golang : How to get HTTP request header information?
+9.4k Golang : Generate random Chinese, Japanese, Korean and other runes
+13.9k Android Studio : Password input and reveal password example
+6.7k Elasticsearch : Shutdown a local node
+6.4k Golang : Process non-XML/JSON formatted ASCII text file example
+5.4k Golang : The Tao of importing package
+5.8k Unix/Linux/MacOSx : Get local IP address