Generalized check_directory_exists and check_file_exists functions.