您的位置:首页 > 其它

用VC遍历文件夹中的所有文件及文件夹

2012-04-26 18:10 260 查看
void CBrowseDlg::BrowseDir( CString strDir, HTREEITEM parent )
{
CFileFind ff;
CString szDir=strDir;
HTREEITEM hSubItem;

if(szDir.Right(1) != "//")
{
szDir += "//";
}

szDir += "*.*";

BOOL res = ff.FindFile( szDir );

while(res)
{
res = ff.FindNextFile();

if( ff.IsDirectory() && !ff.IsDots() )
{
CString strPath = ff.GetFilePath();
CString strTitle = ff.GetFileTitle();
hSubItem = m_fileTree.InsertItem( strTitle, 0, 0, parent );
BrowseDir( strPath, hSubItem );
}
else
{
if( !ff.IsDirectory() && !ff.IsDots() )
{
CString strTitle=ff.GetFileTitle();
m_fileTree.InsertItem( strTitle, 0, 0, parent );
}
}
}
ff.Close();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: