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
+7.6k Golang : Check from web if Go application is running or not
+16.9k Golang : Get future or past hours, minutes or seconds
+14.8k Golang : Find location by IP address and display with Google Map
+8.8k Golang : Write multiple lines or divide string into multiple lines
+13.5k Golang : Reverse IP address for reverse DNS lookup example
+20.2k PHP : Convert(cast) int to double/float
+5.5k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+15.2k Golang : Get current time from the Internet time server(ntp) example
+18.1k Golang : Write file with io.WriteString
+13.1k Golang : How to get year, month and day?
+84.9k Golang : How to convert character to ASCII and back
+5.9k Golang : Scan forex opportunities by Bollinger bands