解题思路是,在百度搜索一下,关键字 c语言 删除目录 递归
void RemoveNullDir(char DirName[MAXDIR])
{
int p;
struct ffblk ff;
char StrTemp[MAXDIR];
strcpy(StrTemp,DirName);
strcat(StrTemp,"\\*.*");
p=findfirst(StrTemp,&ff,0);
while(!p)
{
strcpy(StrTemp,DirName);
strcat(StrTemp,"\\");
strcat(StrTemp,ff.ff_name);
if(((ff.ff_attrib&0xf0)==16||(ff.ff_attrib&0xf0)==48)&&strcmp(ff.ff_name,".")&&strcmp(ff.ff_name,".."))
//如是子目录(不包括.和..子目录)
{
RemoveNullDir(StrTemp); //调用递归函数
}
p=findnext(&ff);//继续查找匹配文件
}//结束while
rmdir(DirName);
}
参考资料:http://topic.csdn.net/t/20010331/20/90988.html