1. 程式人生 > >MFC下使用CFileFind獲取資料夾下所有檔案

MFC下使用CFileFind獲取資料夾下所有檔案

void AddFileFromFolder(const CString strFolderPath)
{
	CString strMatch = strFolderPath + _T("\\*.*");
	CString strFullName;
	CFileFind finder;

	BOOL bWorking = finder.FindFile(strMatch);
	while (bWorking)
	{
		bWorking = finder.FindNextFile();

		if( finder.IsDots() )
			continue;

		if( finder.IsDirectory() )
			AddFileFromFolder(finder.GetFileName() + _T("\\*.*"));
		else
		{
			strFullName = finder.GetFilePath();
			OutputDebugString( (LPCTSTR)(strFullName + L"\n") );//輸出檔名
		}
	}

	finder.Close();
}