January 2018
Intermediate to advanced
340 pages
8h 6m
English
The standard library provides a convenient function for moving a file. Renaming and moving are synonymous terms; if you want to move a file from one directory to another, use the os.Rename() function, as shown in the following code block:
package main
import (
"log"
"os"
)
func main() {
originalPath := "test.txt"
newPath := "test2.txt"
err := os.Rename(originalPath, newPath)
if err != nil {
log.Fatal(err)
}
}
Read now
Unlock full access