8.5 Names and locations
If you wish to change the name of a directory, call rename.
os.rename("recipes/cookies", "recipes/moms-cookies")
os.rename("recipes", "moms-recipes")
We can also rename files. The file stays in the same directory but has a new name.
os.rename("test.py", "chapter-test.py")
os.rename("recipes/cookies/shortbread.docx",
"recipes/cookies/moms-shortbread.docx")
To make a copy of a file’s contents, you can duplicate it using a new name in its current or another directory, or use its current name in a different directory. The shutil module provides several functions to copy files. They take the same arguments.
import shutil
shutil.copyfile("t.py", "test-01.py") # same dir, new name
'test-01.py'
shutil.copy("t.py", "/tests") # different...