shutil
shutil
Directory Operationshutil
provides power to recursive opeartion on directory that pathlib
does not support. We introduce the useful methods copytree
and rmtree
which copy and delete the directory respectively.
shutil.copytree
recursively copy an entire directory tree rooted at src
to a directory named dst
and return the destination directory. The prototype of shutil.copytree
:
shutil.copytree(
src,
dst,=False,
symlinks=None,
ignore=copy2,
copy_function=False,
ignore_dangling_symlinks=False
dirs_exist_ok )
where src
and dst
specify the source and destinition in the file system. If dirs_exist_ok
is not specify, the dst
must not exist.
Python 3.8 introduces the keyword parameter dirs_exist_ok
which dictates whether to raise an exception in case dst
or any missing parent directory already exists.
shutile rmtree
delete an entire directory tree. Prototype of method shutil.rmtree
:
=False, onerror=None) shutil.rmtree(path, ignore_errors