Skip to content

Commit 4ae896a

Browse files
BrianPughdpgeorge
authored andcommitted
shutil: Fix shutil.rmtree to use os.ilistdir instead of os.walk.
1 parent ee286ed commit 4ae896a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

python-stdlib/shutil/shutil.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
_ntuple_diskusage = namedtuple("usage", ("total", "used", "free"))
66

77

8-
def rmtree(top):
9-
for path, dirs, files in os.walk(top, False):
10-
for f in files:
11-
os.unlink(path + "/" + f)
12-
os.rmdir(path)
8+
def rmtree(d):
9+
for name, type, *_ in os.ilistdir(d):
10+
path = d + "/" + name
11+
if type & 0x4000: # dir
12+
rmtree(path)
13+
else: # file
14+
os.unlink(path)
15+
os.rmdir(d)
1316

1417

1518
def copyfileobj(src, dest, length=512):

0 commit comments

Comments
 (0)