|
-
April 16th, 1999, 01:05 AM
#1
How to delete all files in a directory?
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
-
April 16th, 1999, 07:39 AM
#2
Re: How to delete all files in a directory?
Use FindFirstFile/FindNextFile with DeleteFile.
Dave
-
April 16th, 1999, 08:58 AM
#3
Re: How to delete all files in a directory?
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.
-
April 17th, 1999, 12:37 AM
#4
Thank You!
Hi,
Thank you all for the prompt replies.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|