Delete a directory in Go



Tags : golang delete-directory

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 :

http://golang.org/pkg/os/#RemoveAll

Affiliate :

Hire Golang Developers




Tags : golang delete-directory

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