hi,
i want to delete the content of a directory (files and subdiretory included) and the directory itself...
so i wrote the code below which uses a recursive function...
i can delete all the files but not the diretory because i get the error 32 : ERROR_SHARING_VIOLATION.
void DeleteDir(const char *directory)
{
CFileFind finder;
BOOL bWorking;
if (_chdir(directory)!=0)
{
//not exist...
return;
}
DeleteFile();
//look for subdir...
bWorking = finder.FindFile("*.*");
while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDirectory())
{
if (!finder.IsDots())
{
DeleteDir(LPCSTR(finder.GetFilePath()));
}
}
}
if(!RemoveDirectory(directory))
{
char d[256];
sprintf(d,"error %d\n",GetLastError());
MessageBox(NULL, d, "Error", MB_ICONERROR);
}
}
void DeleteFile()
{
CFileFind finder;
BOOL bWorking;
bWorking = finder.FindFile("*.*");
while (bWorking)
{
bWorking = finder.FindNextFile();
DeleteFile(finder.GetFileName());
}
}
the function RemoveDir doesn't work.
but if i write the path like
RemoveDirectory("C:\\test");
it delete it.
how can i do?
thanks in advance
Davide
i want to delete the content of a directory (files and subdiretory included) and the directory itself...
so i wrote the code below which uses a recursive function...
i can delete all the files but not the diretory because i get the error 32 : ERROR_SHARING_VIOLATION.
void DeleteDir(const char *directory)
{
CFileFind finder;
BOOL bWorking;
if (_chdir(directory)!=0)
{
//not exist...
return;
}
DeleteFile();
//look for subdir...
bWorking = finder.FindFile("*.*");
while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDirectory())
{
if (!finder.IsDots())
{
DeleteDir(LPCSTR(finder.GetFilePath()));
}
}
}
if(!RemoveDirectory(directory))
{
char d[256];
sprintf(d,"error %d\n",GetLastError());
MessageBox(NULL, d, "Error", MB_ICONERROR);
}
}
void DeleteFile()
{
CFileFind finder;
BOOL bWorking;
bWorking = finder.FindFile("*.*");
while (bWorking)
{
bWorking = finder.FindNextFile();
DeleteFile(finder.GetFileName());
}
}
the function RemoveDir doesn't work.
but if i write the path like
RemoveDirectory("C:\\test");
it delete it.
how can i do?
thanks in advance
Davide