Golang ProgramsGolang Programs

Move a file from one location to another in Golang

os.Rename() can also move file from one location to another at same time renaming file name.
package main
 
import (
	"log"
	"os"
)
 
func main() {
	oldLocation := "/var/www/html/test.txt"
	newLocation := "/var/www/html/src/test.txt"
	err := os.Rename(oldLocation, newLocation)
	if err != nil {
		log.Fatal(err)
	}
}