Delete Directory in Python: Remove All Files & Folders
You can use the rmtree function in the shutil module to delete a directory and all its contents.
Here is an example:
import shutil
# 要删除的目录路径
directory = '/path/to/directory'
# 删除目录及目录下的文件
shutil.rmtree(directory)
In the above example, replace /path/to/directory with the path to the directory you want to delete.
Please note that the rmtree function will completely delete a directory and its contents, including subdirectories and all files. Therefore, make sure you genuinely want to delete the directory and its contents before using this function.