'FileList'에 해당되는 글 1건

  1. 2009.01.31 폴더에서 파일리스트 가져오기 1
Programming/MFC2009. 1. 31. 16:53

MFC

  1. m_vtFileName.clear();
    m_UserThumbnail.clear();
  2. // 파일 목록을 찾는다.
    CFileFind finder;
    CString strWildCard( m_strDirectory );
  3. strWildCard += "\\*.*";

  4. BOOL bWorking = finder.FindFile( strWildCard );
  5. while( bWorking )
    {
    bWorking = finder.FindNextFile();
  6.   if( finder.IsDots() || finder.IsDirectory() )
      continue;  
     else
     {
      CString filePath = finder.GetFileName();
      filePath.MakeLower();   //대문자 -> 소문자
  7.    //if( IsImageGDIPLUSValid( m_strDirectory + "\\" + filePath ) )  
      if( filePath.Find(".jpg") > 0)
       m_vtFileName.push_back( filePath );  
     }

    finder.Close();
  8.  

API

  1.  m_strThumbnailDir = dir;
    if( m_strThumbnailDir == "" )
    {
     //AfxMessageBox(_T("not define strpath!"));
     m_vtImageName->clear();
     return false;
    }
  2.  CString strExt;
    CString strName;
    CString strPattern;
  3.  BOOL bRC = TRUE;
  4.  HANDLE     hFind = NULL;
    WIN32_FIND_DATA   FindFileData;
    std::vector<CString> VectorImageNames;
  5.  if( m_strThumbnailDir[ m_strThumbnailDir.GetLength() - 1 ] == TCHAR('\\') )
     strPattern.Format( _T("%s*.*"), m_strThumbnailDir );
    else
     strPattern.Format( _T("%s\\*.*"), m_strThumbnailDir );
  6.  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);
  7.   if( FindType( strExt ) ){
  8.    // save the image file name
      VectorImageNames.push_back( strName );
     }
    }
  9.  // 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);
  10.     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
  11.  // close the search handle
    ::FindClose(hFind);
  12.  // 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;
    }
  13.  return FALSE; 
Posted by skensita