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 :
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
Tutorials
+13.7k Golang : How to determine if a year is leap year?
+6.6k Golang : Skip or discard items of non-interest when iterating example
+18.2k Golang : How to remove certain lines from a file
+4.6k Mac OSX : Get disk partitions' size, type and name
+5.6k Fix fatal error: evacuation not done in time problem
+5.2k Golang : Calculate half life decay example
+16.7k Golang : read gzipped http response
+14.2k Golang : How to convert a number to words
+9.5k Golang : How to generate Code 39 barcode?
+23.8k Golang : Use regular expression to validate domain name
+17.9k Golang : Get all upper case or lower case characters from string example
+22.8k Golang : simulate tail -f or read last line from log file example