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
+6.3k Grep : How to grep for strings inside binary data
+31.4k Golang : How to convert(cast) string to IP address?
+6.2k PHP : Proper way to get UTF-8 character or string length
+19k Golang : Calculate entire request body length during run time
+13.8k Golang : Compress and decompress file with compress/flate example
+7.6k Golang : Generate human readable password
+10.4k Golang : Create matrix with Gonum Matrix package example
+23.5k Find and replace a character in a string in Go
+17.9k Golang : Convert IPv4 address to decimal number(base 10) or integer
+4.9k Golang : PGX CopyFrom to insert rows into Postgres database
+4.8k Golang : Calculate a pip value and distance to target profit example
+12k Golang : Get remaining text such as id or filename after last segment in URL path