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
+9.4k Golang : Flip coin example
+7.6k Golang : Sort lines of text example
+4.8k Unix/Linux : How to open tar.gz file ?
+14.9k Golang : Get file permission
+13.9k Golang : Force download file example
+10.5k Golang : Verify Linux user password again before executing a program example
+4.2k Golang : Calculate half life decay example
+24.2k Golang : How to read integer value from standard input ?
+36k Golang : Read a text file and replace certain words
+11k Android Studio : Highlight ImageButton when pressed on example
+11.3k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+4.6k PHP : Convert CSV to JSON with YQL example