Hi,
How do I delete all files in a directory? Right now I am using
system("del c:\directory\*.*)
but it shows a DOS box which is not desirable
Printable View
Hi,
How do I delete all files in a directory? Right now I am using
system("del c:\directory\*.*)
but it shows a DOS box which is not desirable
Use FindFirstFile/FindNextFile with DeleteFile.
Dave
Hi,
below is the code to delete the directory!
BOOL DeleteDirectory( CString DirectoryPath )
{
if ( DirectoryPath.IsEmpty()) //make sure not to delete the Root !
return TRUE ;
CFileFind finder;
DirectoryPath += "\\*.*";
BOOL bWorking = finder.FindFile(DirectoryPath);
while (bWorking)
{
bWorking = finder.FindNextFile();
if (!finder.IsDots()) //skip the dots which denote the current directory
{
DeleteFile((LPCTSTR)finder.GetFilePath());
if (finder.IsDirectory())
{
DeleteDirectory(finder.GetFilePath());
}
}
}
finder.Close();
if (!RemoveDirectory(LPCTSTR( DirectoryPath.Left(DirectoryPath.GetLength()-strlen("\\*.*")) + '\0')))
{
return FALSE;
}
return TRUE;
}
Hope this helps You.
Good Luck.
Yash.
Hi,
Thank you all for the prompt replies.