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
+4.4k Golang : Frobnicate or tweaking a string example
+18.3k Golang : Check if os.Stdin input data is piped or from terminal
+12.7k Golang : How to convert a number to words
+7.1k Golang : Variadic function arguments sanity check example
+26k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+9.1k Golang : Resolve domain name to IP4 and IP6 addresses.
+3.9k Golang : A program that contain another program and executes it during run-time
+4.4k Golang : If else example and common mistake
+6k Golang : Get environment variable
+5.4k CodeIgniter : form input set_value cause " to become & quot
+20.1k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+13.9k Golang : Force download file example