读书人

windows api 编程,该如何解决

发布时间: 2012-04-12 15:46:35 作者: rapoo

windows api 编程
用api函数实现删除一个文件夹,代码如下
int Delete(char *p)
{
HANDLE hFind;
char m[20],n[20],str[20];
struct _WIN32_FIND_DATAA FILEDATA;
if(!RemoveDirectory(p))
{
strcpy(n,"\\");
strcpy(m,p);
strcpy(str,p);
strcat(m,"\\*.*");
hFind=FindFirstFile(m,&FILEDATA);
while(FindNextFile(hFind,&FILEDATA)!=0)
{
if(FILEDATA.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
{
strcat(n,FILEDATA.cFileName);
strcat(str,n);
Delete(str);
}

else
{
strcat(n,FILEDATA.cFileName);
strcat(m,n);
DeleteFile(m);
}
}
}
return 0;
}
void main()
{
Delete("c:\\suifengershi\\xxjk");
getchar();
}
高人指点问题出现在哪?

[解决办法]
RemoveDirectory
The RemoveDirectory function deletes an existing empty directory.

BOOL RemoveDirectory(
LPCTSTR lpPathName // directory name
);
Parameters
lpPathName
[in] Pointer to a null-terminated string that specifies the path of the directory to be removed. The path must specify an empty directory, and the calling process must have delete access to the directory.
Windows NT/2000: In the ANSI

你的程序不管怎么变,最终都没有吧目录中的文件删除,目录一直不空,就一直不能删除目录。在

else
{
strcat(n,FILEDATA.cFileName);
strcat(m,n);
DeleteFile(m);
}
这里已经判断不是目录,那么就删除这个文件啊、、、

读书人网 >C语言

热点推荐