In the Go language, you are allowed to rename and move the existing file to a new path with the help of the Rename() method. This method is used to rename and move a file from the old path to the new path.
- If the given new path already exists and it is not in a directory, then this method will replace it. But OS-specific restrictions may apply when the given old path and the new path are in different directories.
- If the given path is incorrect, then it will throw an error of type *LinkError.
- It is defined under the os package so, you have to import os package in your program for accessing Remove() function.
func Rename(old_path, new_path string) error
- How to Create an Empty File in Golang?
- How to Delete or Remove a File in Golang?
- How to Truncate a File in Golang?
- Checking the Given File Exists or Not in Golang
- How to Read a File Line by Line to String in Golang?
- How to Uncompress a File in Golang?
- Getting the current date and time with timestamp in local and other timezones in Golang
- Difference between var keyword and short declaration operator in Golang
- Anonymous Structure and Field in Golang
- main and init function in Golang
- Golang | Deadlock and Default Case in Select Statement
- How to Remove All Directories and Files in Golang?
- How to Find the Sin and Cos Value of a Number in Golang?
- How to find the capacity of Channel, Pointer and Slice in Golang?
- How to Create and Print Multi Dimensional Slice in Golang?
- Calculating total number of Hours, Days, Minutes and Seconds between two dates in Golang
- How to declare and access pointer variable in Golang?
- How to find the Length of Channel, Pointer, Slice, String and Map in Golang?
- How to use for and foreach loop in Golang?
- How to use Array Reverse Sort Functions for Integer and Strings in Golang?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.