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
+29k Golang : Login(Authenticate) with Facebook example
+24.4k Golang : Daemonizing a simple web server process example
+13.2k Golang : Get dimension(width and height) of image file
+11.3k Golang : Gorilla web tool kit secure cookie example
+16.3k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+6.4k Golang : Reverse by word
+26.6k Golang : Find files by name - cross platform example
+5.4k Linux : Disable and enable IPv4 forwarding
+5.3k Linux/Unix/PHP : Restart PHP-FPM
+12.6k Golang : How to calculate the distance between two coordinates using Haversine formula
+8.7k Golang : Apply Histogram Equalization to color images
+12.5k Golang : Convert IPv4 address to packed 32-bit binary format