是文件夾內(nèi)的任何文件數(shù)量,我需要同時監(jiān)控3個文件(無需多線程,有更好),數(shù)量反饋給編輯框就可以了
2 回答

慕絲7291255
TA貢獻1859條經(jīng)驗 獲得超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; } |
以上為不遞歸子目錄的統(tǒng)計代碼,如果文件不是非常多,那么添加這個函數(shù),然后在對話框的OnTimer定時器響應(yīng)函數(shù)中用定時器做:
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); } |
注意在適當?shù)臅r候(如OnInitDialog中)SetTimer(1,5000);就可以了

撒科打諢
TA貢獻1934條經(jīng)驗 獲得超2個贊
文件個數(shù):遍歷文件夾,CFindFile找"*.*",設(shè)個變量,找到文件,就加個1,這個很容易實現(xiàn)的。
你要怎樣監(jiān)控文件?監(jiān)控指定文件存在與否?
- 2 回答
- 0 關(guān)注
- 162 瀏覽
添加回答
舉報
0/150
提交
取消