I don't have much experience and I'm on a C project where I need to create & delete folders and the program must run on both Linux and Windows.
I saw few solutions but all were either for Windows or Linux but none for both and most uses system(...).
Also, if there is an easy way to delete a folder with it's contents, I'm interrested (for the moment I delete each files one by one and then the folder with remove(...)) Thanks in advance.
With the help of mkdir command, you can create a new directory wherever you want in your system. Just type "mkdir <dir name> , in place of <dir name> type the name of new directory, you want to create and then press enter. Example: mkdir created.
Right click using computer mouse, select New > Folder. Rename it to “ajeet”. 2. Alternatively, we can create a new folder by running a command in the WSL terminal.
The mkdir command in Linux/Unix allows users to create or make new directories. mkdir stands for “make directory.” With mkdir , you can also set permissions, create multiple directories (folders) at once, and much more.
Here is a common 'create directory' method:
void make_directory(const char* name)
{
#ifdef __linux__
mkdir(name, 777);
#else
_mkdir(name);
#endif
}
As for removing directories, you are on the right track, ie:
for the moment I delete each files one by one and then the folder with remove(...)
It is not what you should do in production code, but I had to mention that one liner solution no #ifdef
etc. I am Assuming you run it from the same path you want to create the directory in:
system("mkdir my_dir");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With