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
+11.8k How to tell if a binary(executable) file or web application is built with Golang?
+8.2k Golang : Get all countries phone codes
+5.8k Get website traffic ranking with Similar Web or Alexa
+27.8k Golang : dial tcp: too many colons in address
+14.5k Golang : Find network of an IP address
+7.6k Golang : How to handle file size larger than available memory panic issue
+5.3k Golang : Customize scanner.Scanner to treat dash as part of identifier
+14.1k Golang : How to determine if a year is leap year?
+6.9k Golang : Get expvar(export variables) to work with multiplexer
+10.2k Golang : Identifying Golang HTTP client request
+6.6k Golang : Convert an executable file into []byte example