MCPcopy Index your code
hub / github.com/python/cpython / remove_folder

Method remove_folder

Lib/mailbox.py:518–535  ·  view source on GitHub ↗

Delete the named folder, which must be empty.

(self, folder)

Source from the content-addressed store, hash-verified

516 return result
517
518 def remove_folder(self, folder):
519 """Delete the named folder, which must be empty."""
520 path = os.path.join(self._path, '.' + folder)
521 for entry in os.listdir(os.path.join(path, 'new')) + \
522 os.listdir(os.path.join(path, 'cur')):
523 if len(entry) < 1 or entry[0] != '.':
524 raise NotEmptyError('Folder contains message(s): %s' % folder)
525 for entry in os.listdir(path):
526 if entry != 'new' and entry != 'cur' and entry != 'tmp' and \
527 os.path.isdir(os.path.join(path, entry)):
528 raise NotEmptyError("Folder contains subdirectory '%s': %s" %
529 (folder, entry))
530 for root, dirs, files in os.walk(path, topdown=False):
531 for entry in files:
532 os.remove(os.path.join(root, entry))
533 for entry in dirs:
534 os.rmdir(os.path.join(root, entry))
535 os.rmdir(path)
536
537 def clean(self):
538 """Delete old files in "tmp"."""

Callers

nothing calls this directly

Calls 7

NotEmptyErrorClass · 0.85
listdirMethod · 0.80
rmdirMethod · 0.80
joinMethod · 0.45
isdirMethod · 0.45
walkMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected