linuxbashdirectoryrust-cargormdir

How to remove a project directory that "cargo new" created


I, by mistake, have created a new project directory with cargo new communicator --bin, instead of cargo new communicator --lib.

Then, I tried to remove the entire directory with rmdir --ignore-fail-on-non-empty communicator. This command doesn't generate an error in the next line, but when I look to see if it's removed it's still there!

I wonder why I cannot remove a project directory in this fashion.

I tried both on Atom's Terminal Window and MX Linux Xfce Terminal, but the same result... Also, just in case I performed the same rmdir command as a root, but in vain.

Am I fundamentally doing something wrong here?


Solution

  • Cargo doesn't do anything "special" with the project folder. If you accidentally created a --bin project instead of a library, You can

    1. Delete the communicator bin project with rm -rf communicator where r is for recursive and f is to force remove(in case folder is not empty).

    2. Delete communicator/src/main.rs and create communicator/src/lib.rs.

    The second option has the same effect as deleting the --bin project and creating a library.