【C】复制和删除含有子DIR的DIR(WIN32API)
删除文件夹:void DeleteFolderA(char *szFilePath){
WIN32_FIND_DATAA fd;
char szSearch={0};
strcpy(szSearch,szFilePath);
strcat(szSearch,"*.*");
HANDLE h=FindFirstFileA(szSearch,&fd);
if(h!=INVALID_HANDLE_VALUE)
{
BOOL bRet=TRUE;
while(bRet)
{
bRet=FindNextFileA(h,&fd);
if(stricmp(fd.cFileName,".."))
{
char tmp={0};
strcpy(tmp,szFilePath);
strcat(tmp,fd.cFileName);
if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
strcat(tmp,"\\");
DeleteFolder(tmp);
}
else
{
DeleteFileA(tmp);
}
}
}
FindClose(h);
}
RemoveDirectoryA(szFilePath);
}测试:DeleteFolderA("c:\\windows\\");复制文件夹:**** Hidden Message *****
页:
[1]