Detect and create correct directory.