如何在C中创建文件夹(需要同时在Linux和Windows上运行) [英] How to create a folder in C (need to run on both Linux and Windows)
问题描述
我没有太多经验,我在一个C项目中需要创建&删除文件夹,该程序必须同时在Linux和Windows上运行.
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.
我看到的解决方案很少,但所有解决方案都适用于Windows或Linux,但都无法解决,大多数使用系统(...).
I saw few solutions but all were either for Windows or Linux but none for both and most uses system(...).
此外,如果有一种简便的方法来删除包含其内容的文件夹,我会感到困惑(目前我先一个一个地删除每个文件,然后使用remove(...)删除该文件夹) 预先感谢.
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.
推荐答案
以下是常见的创建目录"方法:
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:
此刻,我先删除每个文件,然后使用remove(...)删除文件夹
for the moment I delete each files one by one and then the folder with remove(...)
这篇关于如何在C中创建文件夹(需要同时在Linux和Windows上运行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!