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
+3.5k Golang : Valued expressions and functions example
+19.8k Golang : Get password from console input without echo or masked
+6.1k Golang : Gorrila mux.Vars() function example
+6k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+25.6k Golang : Find files by name - cross platform example
+30.8k Golang : Convert []string to []byte examples
+7.8k Golang : Write multiple lines or divide string into multiple lines
+11.5k Generate salted password with OpenSSL example
+13.5k Golang : Missing Bazaar command
+7.8k Golang : automatically figure out array length(size) with three dots
+31.5k Delete a directory in Go
+28.3k Golang : How to verify uploaded file is image or allowed file types