add null check for opendir