Check if directory exists and create it if necessary