Golang ProgramsGolang Programs

Rename a file in Golang

package main
 
import (
	"log"
	"os"
)
 
func main() {
	oldName := "test.txt"
	newName := "testing.txt"
	err := os.Rename(oldName, newName)
	if err != nil {
		log.Fatal(err)
	}
}
C:\golang\working-with-files>go fmt example.go

C:\golang\working-with-files>golint example.go

C:\golang\working-with-files>go run example.go

C:\golang\working-with-files>