- Hands-On System Programming with Go
- Alex Guerrieri
- 60字
- 2021-06-24 13:42:29
Move
The os.Rename function makes it possible to change a file name and/or its directory. Note that this operation replaces the destination file if it already exists.
The code for changing a file's name or its directory is as follows:
import "os"
func main() {
if err := os.Rename("file.txt", "../file.txt"); err != nil {
fmt.Println("Error:", err)
}
}