Added an extra test and switched to use isdir() instead of using try