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
+9.7k Golang : Turn string or text file into slice example
+5.4k Golang : If else example and common mistake
+8.7k Golang : HTTP Routing with Goji example
+7.2k Golang : Individual and total number of words counter example
+20.2k nginx: [emerg] unknown directive "passenger_enabled"
+25.9k Mac/Linux and Golang : Fix bind: address already in use error
+27.7k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+8.9k Golang : automatically figure out array length(size) with three dots
+17.5k Convert JSON to CSV in Golang
+23.9k Golang : Upload to S3 with official aws-sdk-go package
+23.4k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+4.8k Unix/Linux : secure copying between servers with SCP command examples