Skip to content

Files

52 lines (29 loc) · 2.02 KB

Python_Delete_entire_directory_tree.md

File metadata and controls

52 lines (29 loc) · 2.02 KB



Template request | Bug report | Generate Data Product

Tags: #python #shutil #delete #folder #file #directory

Author: Florent Ravenel

Description: This notebook will show how to delete an entire directory tree using the shutil library.

Shutil module in Python provides many functions of high-level operations on files and collections of files. It comes under Python’s standard utility modules. This module helps in automating the process of copying and removal of files and directories.

shutil.rmtree() is used to delete an entire directory tree, path must point to a directory (but not a symbolic link to a directory).

References:

Input

Import libraries

import shutil

Setup Variables

  • folder_path: path of the folder to be removed
folder_path = "./my_folder"

Model

Delete entire directory tree

shutil.rmtree(folder_path)

Output

Display result

print(f"Folder {folder_path} deleted.")