MFC
- m_vtFileName.clear();
m_UserThumbnail.clear(); - // 파일 목록을 찾는다.
CFileFind finder;
CString strWildCard( m_strDirectory ); - strWildCard += "\\*.*";
BOOL bWorking = finder.FindFile( strWildCard );- while( bWorking )
{
bWorking = finder.FindNextFile(); - if( finder.IsDots() || finder.IsDirectory() )
continue;
else
{
CString filePath = finder.GetFileName();
filePath.MakeLower(); //대문자 -> 소문자 - //if( IsImageGDIPLUSValid( m_strDirectory + "\\" + filePath ) )
if( filePath.Find(".jpg") > 0)
m_vtFileName.push_back( filePath );
}
}
finder.Close();
API
- m_strThumbnailDir = dir;
if( m_strThumbnailDir == "" )
{
//AfxMessageBox(_T("not define strpath!"));
m_vtImageName->clear();
return false;
} - CString strExt;
CString strName;
CString strPattern; - BOOL bRC = TRUE;
- HANDLE hFind = NULL;
WIN32_FIND_DATA FindFileData;
std::vector<CString> VectorImageNames; - if( m_strThumbnailDir[ m_strThumbnailDir.GetLength() - 1 ] == TCHAR('\\') )
strPattern.Format( _T("%s*.*"), m_strThumbnailDir );
else
strPattern.Format( _T("%s\\*.*"), m_strThumbnailDir ); - hFind = FindFirstFile(strPattern,&FindFileData);
if(hFind == INVALID_HANDLE_VALUE)
{
LPVOID msg;
::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&msg,
0,
NULL);
MessageBox((LPTSTR)msg, _T("fileload error"), MB_OK|MB_ICONSTOP);
::LocalFree(msg);
return FALSE;
}
// filter off the system files and directories
if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) &&
!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) &&
!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY))
{
// test file extension
strName = FindFileData.cFileName;
strExt = strName.Right(3); - if( FindType( strExt ) ){
- // save the image file name
VectorImageNames.push_back( strName );
}
} - // loop through to add all of them to our vector
while (bRC)
{
bRC = ::FindNextFile(hFind, &FindFileData);
if (bRC)
{
// filter off the system files and directories
if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) &&
!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) &&
!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY))
{
// test file extension
strName = FindFileData.cFileName;
strExt = strName.Right(3); - if(FindType(strExt)){
// save the image file name
VectorImageNames.push_back(strName);
}
}
}
else
{
DWORD err = ::GetLastError();
if (err != ERROR_NO_MORE_FILES)
{
LPVOID msg;
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&msg, 0, NULL);
MessageBox((LPTSTR)msg, _T("fileload error"), MB_OK|MB_ICONSTOP);
::LocalFree(msg);
::FindClose(hFind);
return FALSE;
}
}
} // end of while loop - // close the search handle
::FindClose(hFind); - // update the names, if any
if ( !VectorImageNames.empty() )
{
// reset the image name vector
m_vtImageName->clear();
*m_vtImageName = VectorImageNames;
return TRUE;
}
else
{
m_vtImageName->clear();
return TRUE;
} - return FALSE;