shutil.rmtree()
shutil.rmtree() is used to delete an entire directory tree, path must point to a directory.
Example: Suppose the directory and sub-directories are as follow.
# Parent directory:
# Directory inside parent directory:
# File inside the sub-directory:
Python3
# Python program to demonstrate # shutil.rmtree() import shutil import os # location location = "D:/Pycharm projects/w3wiki/" # directory dir = "Authors" # path path = os.path.join(location, dir ) # removing directory shutil.rmtree(path) |
Output:
Refer to the below articles for our complete tutorial on the OS module and Shutil module.
10 Python File System Methods You Should Know
While programming in any language, interaction between the programs and the operating system (Windows, Linux, macOS) can become important at some point in any developer’s life. This interaction may include moving files from one location to another, creating a new file, deleting a file, etc.