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
+12.6k Golang : Convert IPv4 address to packed 32-bit binary format
+26.3k Golang : Encrypt and decrypt data with AES crypto
+13.9k Golang : syscall.Socket example
+7.4k Golang : Error reading timestamp with GORM or SQL driver
+8k Golang : Oanda bot with Telegram and RSI example
+19.4k Golang : Measure http.Get() execution time
+33.3k Golang : How to check if slice or array is empty?
+14.2k Golang : GUI with Qt and OpenCV to capture image from camera
+45.6k Golang : Read tab delimited file with encoding/csv package
+28.7k Golang : Get first few and last few characters from string
+7.9k Golang : Tell color name with OpenCV example