shutile Module

The shutil stands for shell utilities. This allows us to manipulate files.

Copying files and folders #

  • shutil.copy() - Copy individual files.
  • shutil.copytree() - Copy whole folders recursively.
i>>> import shutil, os
i>>> from pathlib import Path
i>>> p = Path.home()
i>>> shutil.copy(p / 'python' / 'bacon.txt', p / 'python/python.bak/')
'/home/akraker/python/python.bak/bacon.txt'
i>>> shutil.copy(p / 'python' / 'bacon.txt', p / 'python/python.bak/bacon2.txt')
PosixPath('/home/akraker/python/python.bak/bacon2.txt')

Moving and renaming files and folders #