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.9k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+11.5k How to tell if a binary(executable) file or web application is built with Golang?
+11.4k SSL : The certificate is not trusted because no issuer chain was provided
+7.6k Golang : Scan files for certain pattern and rename part of the files
+9.2k Golang : Scramble and unscramble text message by randomly replacing words
+20.3k Android Studio : AlertDialog and EditText to get user string input example
+21k Golang : How to get time zone and load different time zone?
+11.1k Golang : How to flush a channel before the end of program?
+12.2k Elastic Search : Return all records (higher than default 10)
+13.2k Golang : Count number of runes in string
+30.5k Golang : Download file example
+16.3k Golang : File path independent of Operating System