Golang : Rename file




No File I/O operations will be complete without the capability to rename file.

Renaming a file in Go is easy. This short tutorial will demonstrate how to rename a file.

renamefile.go

 package main

  import (
 "fmt"
 "os"
  )

  func main() {

 err :=  os.Rename("old_file", "new_file")

 if err != nil {
 fmt.Println(err)
 return
 }
 }

Reference :

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

  See also : Golang : Delete 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