linux下面递归创建目录结构
2014-07-28 17:16
309 查看
目录中的分隔符为‘/’,当存在重复的'//'时候会自动合并一个。
void mkdirs(const char *dir)
{
std::string strPath;
if (strlen(dir) == 0 || dir == nullptr)
{
printf("strlen(dir) is 0 or dir is NULL./n");
return;
}
strPath = dir;
size_t nPos = 0, nIndex = 0;
std::string strSub;
while((nPos = strPath.find('/', nIndex)) != std::string::npos)
{
strSub = strPath.substr(0, nPos);
if(!strSub.empty())
mkdir(strSub.c_str(), 0777);
nIndex = nPos + 1;
while(strPath.length() > nIndex && strPath.at(nIndex) == '/')
{
strPath.replace(nPos, 2, "/");
}
if(strPath.length() <= nIndex)
break;
}
if(strSub.compare(strPath) != 0)
mkdir(strSub.c_str(), 0777);
}
void mkdirs(const char *dir)
{
std::string strPath;
if (strlen(dir) == 0 || dir == nullptr)
{
printf("strlen(dir) is 0 or dir is NULL./n");
return;
}
strPath = dir;
size_t nPos = 0, nIndex = 0;
std::string strSub;
while((nPos = strPath.find('/', nIndex)) != std::string::npos)
{
strSub = strPath.substr(0, nPos);
if(!strSub.empty())
mkdir(strSub.c_str(), 0777);
nIndex = nPos + 1;
while(strPath.length() > nIndex && strPath.at(nIndex) == '/')
{
strPath.replace(nPos, 2, "/");
}
if(strPath.length() <= nIndex)
break;
}
if(strSub.compare(strPath) != 0)
mkdir(strSub.c_str(), 0777);
}
相关文章推荐
- Linux下递归创建目录
- Linux递归创建目录命令
- Linux 目录结构、相关命令(创建、删除、拷贝、移动、更名)
- Linux命令随手记之一:用mkdir的{}参数,用来一次性创建复杂的目录结构
- Linux 下面创建2级目录
- Linux入职基础-7.10_自动创建Makefile入门(实战2:deep目录结构实战)
- linux专题一之文件管理(目录结构、创建、查看、删除、移动)
- linux下创建svn仓库目录结构
- Linux显示目录及目录下面的文件(递归目录)
- linux下面创建多级目录
- Linux入职基础-7.9_自动创建Makefile入门(实战1:Flat目录结构)
- Linux驱动学习 —— 在/sys下面创建目录示例
- 对于每一个Linux学习者来说,了解Linux文件系统的目录结构,是学好Linux的至关重要的一步.,深入了解linux文件目录结构的标准和每个目录的详细功能,对于我们用好linux系统只管重要,下面
- linux学习第三篇 目录结构及创建/删除文件、目录的命令使用
- 工程linux下创建svn仓库目录结构
- Linux入职基础-7.11_自动创建Makefile入门(实战3:shallow目录结构)
- LINUX入门常用命令之目录的创建与删除
- 完美解读Linux文件系统的目录结构(附简明查阅手册)
- Linux的目录结构
- 完美解读Linux中文件系统的目录结构