是文件夾內的任何文件數量,我需要同時監控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 關注
- 164 瀏覽
添加回答
舉報
0/150
提交
取消