[PYTHONMAC-SIG] os.rmdir()

Doug Wyatt doug@sonosphere.com
Mon, 14 Jul 1997 20:33:55 -0400


Hello all,

I'm trying to delete a directory in a Python program (in preparation for
unstuffing a new copy of it...)

I find that os.rmdir() fails with an unknown error 16.

I tried writing this little function to empty out a folder before deleting
it.  It half-worked; one large portion of the tree was deleted, including
many subdirectories, but still rmdir() refused to delete one directory
which the Finder had no trouble trashing (so the directory was not corrupt).

def myrmdir(dirpath):
	#print 'deleting children of',dirpath
	if dirpath[-1] == os.sep: dirpath = dirpath[:-1]
	items = os.listdir(dirpath)
	for f in items:
		if f == '.' or f == '..': continue
		path = dirpath + os.sep + f
		if os.path.isdir(path):
			myrmdir(path)
		else:
			#print 'deleting',path
			os.unlink(path)
	print 'deleting',dirpath
	os.rmdir(dirpath)

Any ideas?  Shall I dig into the source?

Doug


---
Doug Wyatt                      music [,] software
doug@sonosphere.com             http://www.sonosphere.com/
new streaming audio samples:    http://www.sonosphere.com/doug/music.html



_______________
PYTHONMAC-SIG  - SIG on Python for the Apple Macintosh

send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________