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
+38.8k Golang : How do I convert int to uint8?
+21.1k Golang : How to read JPG(JPEG), GIF and PNG files ?
+19.6k Golang : Create and resolve(read) symbolic links
+17.1k Golang : Logging with logrus
+30.9k Golang : Convert []string to []byte examples
+32.7k Golang : convert(cast) bytes to string
+13.8k Golang : Basic authentication with .htpasswd file
+30.5k Golang : Copy directory - including sub-directories and files
+16.8k Golang : Check if a directory exist or not
+8.2k Golang : Extract or copy items from map based on value
+29.2k Golang : Interpolating or substituting variables in string examples
+6.4k Javascript : Push notifications to browser with Push.js