Tuesday, July 14, 2009

MFC - Delete Path Recursive

Want to Delete entire path? Use this




void CMyFileManager::DeletePathRecursive( LPTSTR pszPathToDelete )
{
CString strCurPathToDelete;
CString strCurFileFound;
CFileFind FileFinder;



strCurPathToDelete.Format( _T("%s\\*.*") , pszPathToDelete );

BOOL bWorking = FileFinder.FindFile( strCurPathToDelete );
while ( bWorking )
{
bWorking = FileFinder.FindNextFile();

if ( FileFinder.IsDots() ) continue;

strCurFileFound = FileFinder.GetFilePath();

if ( FileFinder.IsDirectory() )
{
// Found a sub-directory - delete it recursivly:
DeletePathRecursive( strCurFileFound.GetBuffer(0) );

// Delete the sub-directory itself:
TRACE( _T("\nDeleting sub-directory %s") , strCurFileFound );
RemoveDirectory( strCurFileFound.GetBuffer(0) );
}
else
{
// Found a file - delete it:
TRACE( _T("\nDeleting file %s") , strCurFileFound );
DeleteFile( strCurFileFound );
}
}
}

0 תגובות:

Post a Comment

 
Home | About | Link | Link
Simple Proff Blogger Template Created By Herro | Inspiring By Busy Bee Woo Themes