删除目录及目录下所有文件与子目录 (转)[@more@]删除目录及目录下所有
文件与子目录 VC++只提供了删除一个空目录的
函数,而用往往希望删除其下有很多子目录与 文件的目录。为了实现这一功能,我编写了DeleteDirectory 函数,它可以实现 这一功能。 函数原型:BOOL DeleteDirectory(char *DirName); 返回值:成功删除时返回TRUE,否则返回FALSE 参数DirName为要删除的目录名,必须为绝对路径名,如“c:temp"。 函数定义如下: BOOL DeleteDirectory(char *DirName) { CFileFind tempFind; char tempFileFind[200]; sprintf(tempFileFind,"%s*.*",DirName); BOOL I
sfinded=(BOOL)tempFind.FindFile(tempFileFind); while(IsFinded) { IsFinded=(BOOL)tempFind.FindNextFile(); if(!tempFind.IsDots()) { char foundFileName[200]; strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200)); if(tempFind.IsDirectory()) { char tempDir[200]; sprintf(tempDir,"%s%s",DirName,foundFileName); DeleteDirectory(tempDir); } else { char tempFileName[200]; sprintf(tempFileName,"%s%s",DirName,foundFileName); DeleteFile(tempFileName); } } } tempFind.Close(); if(!RemovwDirctory(DirName)) { MessageBox(0,"删除目录失败!","警告信息",MK_OK); return FALSE; } return TRUE; }
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-988964/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10752043/viewspace-988964/