0 votes
1 view
in Python by (47.8k 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: 

os.remove("/folder_name")

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

1 Answer

0 votes
by (107k 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.

shuti.rmtree():-

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

shutil.rmtree('/folder_name')

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.8k 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 !


Categories

...