Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

I am getting an 'access is denied' error when I attempt to delete a folder that is not empty. I used the following command in my attempt: 


What is the most effective way of removing/deleting a folder/directory that is not empty?

1 Answer

0 votes
by (106k points)

For removing/deleting any folder that is not empty with Python we have a standard library which is known as shutil. This library provides the function shutil.rmtree() which removes/deletes the non-empty folder.


This function deletes an entire directory tree; the path that must point to a directory (but not a symbolic link to a directory) such kind of errors are handled by calling a handler specified by raising an exception.

The following code illustrates the use of the shutil library and shutil.rmtree() function:-

import shutil


For more information, kindly refer to our Python course. 

Related questions

0 votes
1 answer
0 votes
1 answer
asked Sep 16, 2019 in Java by Anvi (10.2k points)
0 votes
2 answers
asked Aug 23, 2019 in Python by Sammy (47.6k points)
+1 vote
2 answers
asked May 30, 2019 in Python by Ritik (3.5k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.6k answers


108k users

Browse Categories