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
+7.5k Golang : Detect sample rate, channels or latency with PortAudio
+5.4k Golang : Get S3 or CloudFront object or file information
+26.7k Golang : How to check if a connection to database is still alive ?
+6.6k Golang : Totalize or add-up an array or slice example
+15.2k Golang : Accurate and reliable decimal calculations
+27.4k Golang : Convert CSV data to JSON format and save to file
+5.2k Responsive Google Adsense
+25.7k Golang : How to write CSV data to file
+19.1k Golang : Display list of time zones with GMT
+6.5k Golang : Map within a map example
+9.6k Golang : Read file with ioutil
+39k Golang : How to iterate over a []string(array)