递归创建目录、删除目录
windows api中没有提供现成的多层创建目录、删除目录。这里修改了部分代码实现递归创建目录、删除目录。
//删除目录
bool deletedirectory(char* sdirname)
{
cfilefind tempfind;
char stempfilefind[200] ;
sprintf(stempfilefind,"%s\\*.*",sdirname);
bool isfinded = tempfind.findfile(stempfilefind);
while (isfinded)
{
isfinded = tempfind.findnextfile();
if (!tempfind.isdots())
{
char sfoundfilename[200];
strcpy(sfoundfilename,tempfind.getfilename().getbuffer(200));
if (tempfind.isdirectory())
{
char stempdir[200];
sprintf(stempdir,"%s\\%s",sdirname,sfoundfilename);
deletedirectory(stempdir);
}
else
{
char stempfilename[200];
sprintf(stempfilename,"%s\\%s",sdirname,sfoundfilename);
deletefile(stempfilename);
}
}
}
tempfind.close();
if(!removedirectory(sdirname))
{
return false;
}
return true;
}
// 判断目录是否存在
bool folderexists(cstring s)
{
dword attr;
attr = getfileattributes(s);
return (attr != (dword)(-1) ) &&
( attr & file_attribute_directory);
}
// 创建目录
bool createdir(cstring p)
{
int len=p.getlength();
if ( len <2 ) return false;
if('\\'==p[len-1])
{
p=p.left(len-1);
len=p.getlength();
}
if ( len <=0 ) return false;
if (len <=3)
{
if (folderexists(p))return true;
else return false;
}
if (folderexists(p))return true;
cstring parent;
parent=p.left(p.reversefind('\\') );
if(parent.getlength()<=0)return false;
bool ret=createdir(parent);
if(ret)
{
security_attributes sa;
sa.nlength=sizeof(security_attributes);
sa.lpsecuritydescriptor=null;
sa.binherithandle=0;
ret=(createdirectory(p,&sa)==true);
return ret;
}
else
return false;
}

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

Atom编辑器mac版下载
最流行的的开源编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

SublimeText3汉化版
中文版,非常好用

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。