To rename a directory in Go, you can use the os.Rename()
function. The function takes two arguments: the old path of the directory and the new path of the directory.
Here's an example code that renames a directory named old_dir
to new_dir
:
main.go193 chars17 lines
Make sure you have the appropriate permission to rename the directory. If the directory does not exist or if there's any other error, os.Rename()
will return an error which you can handle accordingly.
gistlibby LogSnag