The following test
import os
try:
os.rmdir('1')
except:
pass
os.mkdir('1')
os.chdir('1')
os.rmdir('../1')
fails like this (both in python2 and python3):
D:>python2.7 rmdir.py
Traceback (most recent call last):
File "rmdir.py", line 8, in <module>
os.rmdir('../1')
OSError: [Errno 16] Resource busy: '../1'
D:>python3.9 rmdir.py
Traceback (most recent call last):
File "D:/Coding/Tests/python/rmdir.py", line 8, in <module>
os.rmdir('../1')
OSError: [Errno 16] Resource busy: '../1'
Which is expected because on OS/2 you can't delete a directory which is the current one (on Linux and BSD this is allowed and the test succeeds). A solution is to just chdir("..") before calling the underlying Posix rmdir function in the implementation of os.rmdir. It will always work provided we are not deleting the root drive (which is impossible anyway).
The following test
fails like this (both in python2 and python3):
Which is expected because on OS/2 you can't delete a directory which is the current one (on Linux and BSD this is allowed and the test succeeds). A solution is to just
chdir("..")before calling the underlying Posixrmdirfunction in the implementation ofos.rmdir. It will always work provided we are not deleting the root drive (which is impossible anyway).