rustrust-cargo

How do I create some folders and then a file (in this case main.c)?


//Create folders and main.c
    let folders = format!("{}/src/main.c", name);

    match fs::create_dir_all(&folders) {
        Err(why) => {
            println!("Failed to create folders: {why}");
            return false;
        }
        Ok(_) => {}
    }
    

I want [name]/src to be created as a folder, but main.c to be created as a file. Right now, it creates them all as a folder, (including main.c)


Solution

  • Right now, it creates them all as a folder, (including main.c)

    Because that's what `create_dir_all` does.

    Just create the file separately after using creating the directories.