added a try/catch for detecting errors when processing directories