Ensure that the directory stream is closed after deletion