I don't have much experience and I'm on a C project where I need lớn create và delete folders and the program must run rẩy 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 lớn delete a thư mục with it's contents, I'm interrested (for the moment I delete each files one by one and then the thư mục with remove(...)) Thanks in advance.

asked Apr 24, năm trước at 14:33

2

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 thư mục with remove(...)

alk

70.8k10 gold badges109 silver badges264 bronze badges

answered Apr 24, năm trước at 14:42

3

It is not what you should vì thế in production code, but I had lớn mention that one liner solution no #ifdef etc. I am Assuming you run rẩy it from the same path you want lớn create the directory in:

system("mkdir my_dir");

answered Apr 24, năm trước at 14:39

As I know, you can use the cd (change directory) command lớn create thư mục. You can use the rmdir command lớn delete empty directories. If you want lớn delete the directory with its contents, use rm -rf name-of-the-directory. The -rf specifies lớn force the deletion and lớn vì thế it recursively.

You can use these using the command line, but if you want lớn vì thế this programmatically, I'd say that PHP is suitable lớn vì thế such.

answered Apr 24, năm trước at 14:40

2