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
+20.5k Golang : Match strings by wildcard patterns with filepath.Match() function
+11.2k Golang : Listen and Serve on sub domain example
+13k Golang : ROT47 (Caesar cipher by 47 characters) example
+10.7k Golang : Clean formatting/indenting or pretty print JSON result
+11.9k Golang : Handle or parse date string with Z suffix(RFC3339) example
+5.6k Golang : Spell checking with ispell example
+3.8k Facebook : How to place save to Facebook button on your website
+36.5k Golang : Comparing date or timestamp
+5.1k Golang : Scan forex opportunities by Bollinger bands
+13.8k Golang : How to check for empty array string or string?
+24.6k Golang : missing Mercurial command
+17.2k Golang : Read binary file into memory