mfc--get all the files under the folder and display them on the CListCtrl

Source: Internet
Author: User



VS2015,
CListCtrl initialization. Note that the View property of the control needs to be set to report!!!!
BOOL Cloadfileserverdlg::oninitdialog ()
{
......
Plistctr.deleteallitems (); Plistctr.insertcolumn (0, _t ("file name"), Lvcfmt_center, -); Plistctr.insertcolumn (1, _t ("File Type"), Lvcfmt_center, -); Plistctr.insertcolumn (2, _t ("File Size"), Lvcfmt_center, $); Plistctr.insertcolumn (3, _t ("Storage Path"), Lvcfmt_left, -);
......
}
//list out FilesvoidCloadfileserverdlg::getfilelist (Char*szpath) //parameter is a folder path, such as: "C:\\users\\foreverroad\\desktop\\serverimg"    {Plistctr.deleteallitems ();    CFileFind Finder; //set up the CString object to retrieve the matching stringCString Strwildcard (szpath); Strwildcard+ = _t ("\\*.*"); //File Internal SearchBOOL bworking =Finder.    FindFile (Strwildcard); intI//For positioningcharacter, as subscript    intindex =0;//For list indexCString FontName, Lasttype, filepath,filename,filesize;//Storing cut results     while(bworking) {bworking=Finder.        FindNextFile (); FileName=Finder. GetFileName ();
     //Assuming the folder is full of pictures, get the picture file length imageSize=Finder. GetLength (); if(FileName! = _t (".") && filename! = _t ("..") ) {filepath=Finder. GetFilePath (); for(i =0; i < filename. GetLength (); i++) { if(Filename[i] = ='.') {FontName= filename. Mid (0, i); Lasttype= filename. Mid (i+1, filename. GetLength ()); FileSize. Format (_t ("%d"), imagesize/1024x768); FileSize+="k"; Plistctr.insertitem (index, fontname); Plistctr.setitemtext (Index,1, Lasttype); Plistctr.setitemtext (Index,2, FileSize); Plistctr.setitemtext (Index,3, filepath); }} Index++; }} finder. Close ();}

Folder internal content, from CMD view:

  

Program Run Result:

  

mfc--get all the files under the folder and display them on the CListCtrl

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.