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
+9k Golang : Convert file content to Hex
+7.7k Golang : GMail API create and send draft with simple upload attachment example
+24.1k Golang : How to read integer value from standard input ?
+4.1k Golang : Constant and variable names in native language
+6.1k Nginx : How to block user agent ?
+10.8k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+5.7k Mac/Linux/Windows : Get CPU information from command line
+4.5k Clean up Visual Studio For Mac installation failed disk full problem
+11.3k Swift : Convert (cast) Int or int32 value to CGFloat
+7k Golang : Reverse text lines or flip line order example
+6.5k Golang : Generate human readable password
+7.7k Golang : Write multiple lines or divide string into multiple lines