为了账号安全,请及时绑定邮箱和手机立即绑定

关于VC如何实时获取文件夹内文件数量的问题?求指教

关于VC如何实时获取文件夹内文件数量的问题?求指教

C C++
梵蒂冈之花 2023-03-02 17:13:07
是文件夹内的任何文件数量,我需要同时监控3个文件(无需多线程,有更好),数量反馈给编辑框就可以了
查看完整描述

2 回答

?
慕丝7291255

TA贡献1859条经验 获得超6个赞

int CountDirectory(CString path)     int count = 0;     CFileFind finder;     BOOL working = finder.FindFile(path + "\\*.*");     while (working)    {        working = finder.FindNextFile();         if (finder.IsDots())             continue        if (!finder.IsDirectory())             count++;         return count; }

以上为不递归子目录的统计代码,如果文件不是非常多,那么添加这个函数,然后在对话框的OnTimer定时器响应函数中用定时器做:


void CDialog1::OnTimer(UINT nIDEvent) {    // TODO: Add your message handler code here and/or call default    if (nIDEvent==1)    {        int i = CountDirectory("目录1");        CString str;        str.Format("%d",i);        GetDlgItem(IDC_EDIT1)->SetWindowText(str);    }    CDialog::OnTimer(nIDEvent);}

 注意在适当的时候(如OnInitDialog中)SetTimer(1,5000);就可以了


查看完整回答
反对 回复 2023-03-06
?
撒科打诨

TA贡献1934条经验 获得超2个赞

文件个数:遍历文件夹,CFindFile找"*.*",设个变量,找到文件,就加个1,这个很容易实现的。
你要怎样监控文件?监控指定文件存在与否?

查看完整回答
反对 回复 2023-03-06
  • 2 回答
  • 0 关注
  • 144 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号