메뉴 바로가기

서브메뉴 바로가기

본문 바로가기

logo

C/C++/MFC

FILE 파일 리스트 가져오기

2009.06.16 13:17

WhiteAT 조회 수:15801

파일 리스트를 가져오는 예제 입니다.

     WATFileList.JPG

 
void CFileListDlg::OnReadButton() 
{
    ClearFileList();
    
    UpdateData(TRUE);
    CFileFind finder;

    CString strPath,strTest;
    SHFILEINFO shInfo;
    LIST_ITEM* pListItem;
    pListItem=new LIST_ITEM;    


    strPath = m_strPath+":\\";

    strPath+="*.*";
    CString strFileSize;

    CFileStatus fStatus;
    if( finder.FindFile(strPath) )
    {
        BOOL bFlag=true;
        

        while(bFlag)
        {
            bFlag=finder.FindNextFile();
            SHGetFileInfo(finder.GetFilePath(),0,&shInfo,sizeof(SHFILEINFO),SHGFI_TYPENAME|SHGFI_SYSICONINDEX);

            if(!finder.IsDots())
            {
                CFile::GetStatus(finder.GetFilePath(),fStatus);

                pListItem->strName = finder.GetFileName();
                pListItem->dwFullSize = finder.GetLength();
                strFileSize.Format("%d",pListItem->dwFullSize);
                m_listFile.InsertRow(m_listFile.GetItemCount(),2,pListItem->strName,strFileSize);                    

            }
        }
    }        
}