c_cpp Ç遍历,创建指定目录下的文件.C
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp Ç遍历,创建指定目录下的文件.C相关的知识,希望对你有一定的参考价值。
static int mymkdir(const char * path)
{
int result;
result = mkdir(path, 0755);
if(result && EEXIST == errno)
result = 0;
return result;
}
/* 这是一个完美的递归函数*/
static void gendir(char * path)
{
char * pos;
if(mymkdir(path))
{
pos = strrchr(path, '/');
if(pos)
{
*pos = 0; /* 处理现场*/
gendir(path);
*pos = '/'; /* 恢复现场*/
(void) mymkdir(path);
}
}
}
static FILE * make_new_file(char * absfile)
{
FILE * fp;
char * pos;
fp = fopen(absfile, "w+");
if(NULL == fp)
{
pos = strrchr(absfile, '/');
if(NULL != pos)
{
*pos = 0; /* 处理现场*/
gendir(absfile);
*pos = '/'; /* 还原现场*/
fp = fopen(absfile, "w+");
}
}
return fp;
}
以上是关于c_cpp Ç遍历,创建指定目录下的文件.C的主要内容,如果未能解决你的问题,请参考以下文章