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
+14.4k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+11.3k Golang : Remove or trim extra comma from CSV
+6.3k Android Studio : How to detect camera, activate and capture example
+16.4k Golang : Upload/Receive file progress indicator
+6.3k Golang : File system scanning
+12.1k Golang : error parsing regexp: invalid or unsupported Perl syntax
+21.1k Generate checksum for a file in Go
+28.4k Golang : How to verify uploaded file is image or allowed file types
+7.4k Golang : Generate Datamatrix barcode
+7.9k Golang : How to use Gorilla webtoolkit context package properly
+11.7k Golang : Skip blank/empty lines in CSV file and trim whitespaces example