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
+4.5k Golang : fmt.Println prints out empty data from struct
+7.1k Golang : HTTP Server Example
+18.3k Golang : Determine if directory is empty with os.File.Readdir() function
+15k Golang : Execute terminal command to remote machine example
+6.1k Golang : Trim everything onward after a word
+10.2k Golang : Post data with url.Values{}
+10.7k Golang : Perform sanity checks on filename example
+13.1k Golang : Reset buffer example
+8.2k Golang : How to get ECDSA curve and parameters data?
+5.4k CodeIgniter : form input set_value cause " to become & quot
+8.7k Golang : Identifying Golang HTTP client request
+16.9k Golang : Iterating Elements Over A List