Fix directory replacing and deleting.