Removing a Directory
shutil.rmtree() is used to delete an entire directory tree, the path must point to a directory (but not a symbolic link to a directory).
Syntax: shutil.rmtree(path, ignore_errors=False, onerror=None)
Parameters:
path: A path-like object representing a file path. A path-like object is either a string or bytes object representing a path.
ignore_errors: If ignore_errors is true, errors resulting from failed removals will be ignored.
oneerror: If ignore_errors is false or omitted, such errors are handled by calling a handler specified by onerror.
Python3
# Python program to demonstrate # shutil.rmtree() import shutil import os # location location = "csv/gfg/" # directory dir = "dest" # path path = os.path.join(location, dir ) # removing directory shutil.rmtree(path) |
Shutil Module in Python
Shutil module offers high-level operation on a file like a copy, create, and remote operation on the file. It comes under Python’s standard utility modules. This module helps in automating the process of copying and removal of files and directories. In this article, we will learn this module.