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.
Example
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)
}
}
Most Helpful This Week
Golang Changing permissions, ownership, and timestamps
Go program to add or append content at the end of text file
Go program to extracting or unzip a Zip format file
Golang Create Copy of a file at another location
Go program to Create directory or folder if not exist
Go program to compress list of files into Zip file
Go program to read list of files inside Zip file
Reduce file size
Go program to read a text file character by character
Get file information in Golang