是文件夹内的任何文件数量,我需要同时监控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);就可以了
- 2 回答
- 0 关注
- 144 浏览
添加回答
举报
0/150
提交
取消