以编程方式递归创建目录

发布于 2024-10-09 08:21:20 字数 208 浏览 0 评论 0原文

我希望我的程序创建一个位于命令参数路径的文件,即program /home/user/directory/that/doesnt/exist/file。如果该目录不存在,fopen 将无法打开该文件,因此程序必须创建目录。我是否必须编写自己的循环来检测每个斜杠和每个目录的 mkdir 或者是否有一个函数可以自动执行此操作?

I want my program to create a file located at the path of the command parameter, i.e. program /home/user/directory/that/doesnt/exist/file. If the directory doesn't exist, fopen will fail to open the file, so the program would have to create the directories. Would I have to program my own loop to detect each slash and mkdir each directory or is there a function to do this automatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我早已燃尽 2024-10-16 08:21:20

有人为您编写了代码: mkpath( )

或者,如果您对使用 system() 感到满意,那么您可以使用 system("mkdir -p /your/path/here");

Someone coded it for you: mkpath()

Or if you're satisfied using system(), then you can use system("mkdir -p /your/path/here");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文