Golang : Delete file
Deleting file in Go is simple. This short tutorial will demonstrate how to delete a file.
Let choose a file deleteme.file
as target practice and the code example below will remove the deleteme.file
when executed.
deletefile.go
package main
import (
"fmt"
"os"
)
func main() {
err := os.Remove("deleteme.file")
if err != nil {
fmt.Println(err)
return
}
}
Reference :
See also : Golang : Rename file
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
+14k Golang : How to convert a number to words
+15.2k Golang : invalid character ',' looking for beginning of value
+11.3k Golang : Find age or leap age from date of birth example
+22.7k Golang : Gorilla mux routing example
+5.5k Golang : Struct field tags and what is their purpose?
+7.1k Golang : Not able to grep log.Println() output
+8.4k Golang : Set or add headers for many or different handlers
+18.2k Golang : How to get hour, minute, second from time?
+7.3k Gogland : Single File versus Go Application Run Configurations
+7.1k Golang : File system scanning
+14.2k Golang : Send email with attachment(RFC2822) using Gmail API example
+15k Golang : Get query string value on a POST request