Golang : Delete file



Tags : golang delete

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 :

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

Affiliate :

Hire Golang Developers


  See also : Golang : Rename file



Tags : golang delete

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