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
+6.7k Golang : Find the longest line of text example
+15.9k Golang : Generate universally unique identifier(UUID) example
+15.7k Golang : Get current time from the Internet time server(ntp) example
+19.4k Golang : Close channel after ticker stopped example
+11.1k Golang : Calculate Relative Strength Index(RSI) example
+18.3k Golang : Read binary file into memory
+9.9k CodeIgniter : Load different view for mobile devices
+11.7k Golang : convert(cast) float to string
+10.8k Golang : Sieve of Eratosthenes algorithm
+12.6k Golang : Listen and Serve on sub domain example
+11.3k Use systeminfo to find out installed Windows Hotfix(s) or updates
+40.9k Golang : How to check if a string contains another sub-string?