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.1k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+12.6k Golang : Reverse IP address for reverse DNS lookup example
+9.3k Golang : Convert file unix timestamp to UTC time example
+14.9k Golang : Delete files by extension
+14.2k Golang : Get query string value on a POST request
+7.7k Golang : Combine slices but preserve order example
+3.8k JavaScript: Add marker function on Google Map
+4.9k Get website traffic ranking with Similar Web or Alexa
+11.7k Golang : Pass database connection to function called from another package and HTTP Handler
+3.6k Javascript : Detect when console is activated and do something about it
+7.2k Golang : How To Use Panic and Recover
+22.7k Golang : Generate MD5 checksum of a file