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
+25.3k Golang : Generate MD5 checksum of a file
+36.2k Golang : Convert(cast) int64 to string
+15.4k Golang : Force download file example
+12.6k Golang : Add ASCII art to command line application launching process
+15.9k Golang : Generate universally unique identifier(UUID) example
+6.4k Golang : Calculate diameter, circumference, area, sphere surface and volume
+29.5k Golang : Record voice(audio) from microphone to .WAV file
+6.3k Golang : Break string into a slice of characters example
+5.5k PHP : Convert CSV to JSON with YQL example
+5.2k Python : Convert(cast) string to bytes example
+22.6k Golang : Strings to lowercase and uppercase example
+10.1k Golang : Text file editor (accept input from screen and save to file)