How to create a folder in C (you need to run both on Linux and Windows)

I don’t have much experience, and I am in project C, where I need to create and delete folders, and the program should work on both Linux and Windows.

I saw several solutions, but all of them were either for Windows or for Linux, but neither (nor for most of them use system (...).

In addition, if there is an easy way to delete a folder with its contents, I am intrigued (at the moment I delete each file one by one, and then the folder with the deletion (...)) Thanks in advance.

+4
source share
3 answers

Here is a general directory creation method:

void make_directory(const char* name) 
   {
   #ifdef __linux__
       mkdir(name, 777); 
   #else
       _mkdir(name);
   #endif
   }

, , :

, (...)

+6

, , , liner no #ifdef .. , , :

system("mkdir my_dir");
+1

, cd ( ) . rmdir . , rm -rf name-of-the-directory. -rf .

, , , PHP .

-6
source

Source: https://habr.com/ru/post/1537908/


All Articles