Fixing UnboundLocalError when attempting to process nonexisting dir