Danny
Danny

Reputation: 334

How to delete a complete directory tree as quick as possible? Python

This is what I do but takes forever:

>>> import shutil,os
>>> for d in os.listdir("."):
...     if os.path.isdir(d):
...         shutil.rmtree(d)

Directories are full of files in the order of several thousands files.

What is the fastest way to do it instead?

Upvotes: 0

Views: 1096

Answers (1)

favoretti
favoretti

Reputation: 30167

Unfortunately that's FS speed-bound. There's no real way to speed it up if directories are filled up with many files.

Upvotes: 5

Related Questions