如何在 C 中创建文件夹(需要在 Linux 和 Windows 上运行) [英] How to create a folder in C (need to run on both Linux and Windows)

查看:19
本文介绍了如何在 C 中创建文件夹(需要在 Linux 和 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆