Python – Module shutil
To import module enter:
import shutil
Move, copy and delete files
Functions | What they do |
---|---|
shutil.copy(source, destination) | Will copy the source file in the destination folder If a filename is mentioned in destination it will create a copy and give the new name we defined otherwise it will keep the same name |
shutil.copytree(source, destination) | Copy a folder, files and sub folders in another folder |
shutil.move(source, destination) | Move a file or folder in another folder |
Rename: there is no rename function Use shutil.move(orginalname, newname) | Rename file |
shutil.rmtree(‘folder’) | It will permanently delete all files/subdirectories from the folder. . [<!> tip: be sure to print() the files to be deleted before doing it]. To send to the trash, you will need to install the third party module send2trash |