import shutil #importing show utilities module
shutil.copy('F:\\Example\\something.txt', 'F:\\Example2')
There is a copy of something.txt in the Example2 folder.
Rename and copy at the same time can be done by specifying the file name for the destination.
shutil.copy('F:\\Example\\something.txt', 'F:\\Example2\\newName.txt')
import os
os.listdir('F:\\Example2')
To copy entire folders:
shutil.copytree('F:\\Example','F:\\Example2\\Example_backup')
os.listdir('F:\\Example2')
copied the folder 'Example' to the Example2 folder with name 'Example_backup'.
shutil.move('F:\\Example\\something.txt','F:\\Example2\\something2.txt')
os.listdir('F:\\Example2')
There is no rename function in shutil, instead we move the file to the same destination with new name.
shutil.move('F:\\Example2\\Example_backup','F:\\Example2\\backup_Example')
os.listdir('F:\\Example2')