Fix IOErrors when directory not existing