C非空フォルダの削除を実現
1725 ワード
/*
: rd.c
----------------------------------------------------
c ,
, ,
,
, 。
: VC6 ,
c 。 VC6 findclose c
closedir() 。
----------------------------------------------------
2010.4.28 ( ) ,
----------------------------------------------------
*/
#include
#include
#include
#include
/*
:
const char* dirPath
: ,
: 0
-1 , ,
*/
int removeDir(const char* dirPath)
{
struct _finddata_t fb; //
char path[250];
long handle;
int resultone;
int noFile; //
noFile = 0;
handle = 0;
//
strcpy(path,dirPath);
strcat (path,"/*");
handle = _findfirst(path,&fb);
//
if (handle != 0)
{
// ,
while (0 == _findnext(handle,&fb))
{
//windows , , “..”,
noFile = strcmp(fb.name,"..");
if (0 != noFile)
{
//
memset(path,0,sizeof(path));
strcpy(path,dirPath);
strcat(path,"/");
strcat (path,fb.name);
// 16, ,
if (fb.attrib == 16)
{
removeDir(path);
}
// , 。 , 。
else
{
remove(path);
}
}
}
// , 。 , c closedir
// : Handle , 。
_findclose(handle);
}
//
resultone = rmdir(dirPath);
return resultone;
}