C/C++创建多级目录
工作中没有小事:点石成金,滴水成河,只有认真对待自己所做的一切事情,才能克服万难,取得成功。
转载:https://blog.csdn.net/lenkco/article/details/123306898
转载:https://blog.51cto.com/u_15414551/4399691
#include <io.h> #include <direct.h> #include <string> void ToUnixPath( std::string& s) { std::string::size_type pos = 0; while ((pos = s.find('\\', pos)) != std::string::npos) { s.replace(pos, 1, "/"); pos = pos + 2; } } void createMultiDir(const std::string& strPath) { std::string path = strPath; ToUnixPath(path); if (path[path.length() - 1] != '/') { path += '/'; } std::string::size_type pos = 0; std::string::size_type prevpos = 0; std::string tempStr(path); std::string strFolderPath; std::string stdFolderName; while ((pos = tempStr.find('/', pos)) != std::string::npos) { strFolderPath = tempStr.substr(0, pos); stdFolderName = tempStr.substr(prevpos, pos - prevpos); if (_access(strFolderPath.data(), 0) == 0)//目录存在 { pos = pos + 1; prevpos = pos; continue; } _mkdir(strFolderPath.data()); pos = pos + 1; prevpos = pos; } } int main() { std::string path = "F:/dir/Folder/test/123"; createMultiDir(path); getchar(); return 0; }
分类:
C++
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
2016-06-30 使用VS2010开发Qt程序的一点经验(转载)