Get directory before the try/except block, if it throws an error the directory doesn't need to be changed back in the finally block.