[PYTHONMAC-SIG] P.S. os.rmdir()

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


As usual there's nothing like posting a request for help to make one feel
silly enough to dig further oneself :)

I did a TVB in Macsbug on HDelete and discovered that it's returning -47,
and GUSI is looking to see whether the directory's empty, returning 16 if
it is (a busy error) or 66 if it's not (directory not empty).

I quit Python and restarted it and was able to delete the directory.

This tells me that some Python component made a working directory for the
folder being deleted.  I think this may have been from an earlier action
where I was sending AppleEvents to CodeWarrior, telling it to open project
files that were in the directory that couldn't be deleted.

CWGUSI 1.8 contains no calls to OpenWD.

The Python source contains one, in opendir.c's opendir().  In Python's C
source, closedir() seems to always get called after opendir(), except in
the case of an out-of-memory failure.

...

Doug



~~~~~~~~~~~~~~~~~~~~~~~~~~~

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
_______________