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
+11.3k Golang : Remove or trim extra comma from CSV
+9.6k Golang : Bubble sort example
+5k Golang : Extract unicode string from another unicode string example
+4.5k Swift : Convert string array to array example
+15.7k Golang : How to tell if a file is compressed either gzip or zip ?
+13.5k Golang : Execute function at intervals or after some delay
+7.1k Prevent Write failed: Broken pipe problem during ssh session with screen command
+19.2k Golang : Pipe output from one os.Exec(shell command) to another command
+12.1k Golang : Read from buffered reader until specific number of bytes
+11.6k Golang : Transform comma separated string to slice example
+26.8k Golang : Read, Write(Create) and Delete Cookie example
+11.3k Golang : Covert map/slice/array to JSON or XML format