⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_27160.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:27160 发表者:尹志安 发表日期:2003-01-08 21:44:46
<br>主题:如何将一个目录下的所有文件读出,并在显示出来?
<br>内容:我想读出一个目录下的所有文件,最好是在列表控件显示出来!<BR>有点像资源管理器!<BR>不知哪位高手能够帮帮忙啊!<BR>谢谢了!<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:lin 回复日期:2003-01-09 08:27:04
<br>内容:用CFileFind类吧,读出所有文件,再将它添加到列表控件<BR>void CMainFrame::FindAllFile(CString strDir)<BR>{<BR>CString strName;<BR>strName.Format("%s\\*.*",strDir);&nbsp;&nbsp; //strDir:你要查找的目录<BR>char chFile[100];<BR>char chTemp[100];<BR>CFileFind find;<BR>BOOL bFinished=find.FindFile(strName);<BR>while(bFinished)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp; bFinished =f ind.FindNextFile();<BR>&nbsp;&nbsp;&nbsp;&nbsp; if (!find.IsDots())<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;strcpy(chTemp, find.GetFileName().GetBuffer(100));<BR>&nbsp;&nbsp;&nbsp;&nbsp;sprintf(chFile, "%s\\%s", strDir, chTemp);<BR>&nbsp;&nbsp;&nbsp;&nbsp;TRACE("%s\n",chFile);<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(find.IsDirectory())&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FindAllFile(chFile);<BR>&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//chFile&nbsp;&nbsp;为文件的完整路径<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//将信息添加到列表控件的代码<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>}<BR>find.Close();<BR>}
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:bird 回复日期:2003-01-09 09:10:37
<br>内容:http://www.codeguru.com/treeview/DirTreeCtrl.htm<BR><BR>这儿有个类,你可以用用..
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:尹志安 回复日期:2003-01-09 09:54:58
<br>内容:请教大虾:<BR>我在编译时有如下错误:<BR>C:\test\testDlg.cpp(188) : error C2065: 'nbsp' : undeclared identifier<BR>“nbsp”我不知是何玩意,能讲一讲吗?<BR>我的代码如下:<BR>void CTestDlg::FindAllFile(CString strDir)<BR>{<BR>&nbsp;&nbsp;CString strName;<BR>&nbsp;&nbsp;strName.Format("%s\\*.*",strDir);<BR>&nbsp;&nbsp;int i=0;<BR>&nbsp;&nbsp;char chFile[100];<BR>&nbsp;&nbsp;char chTemp[100];<BR>&nbsp;&nbsp;CFileFind find;<BR>&nbsp;&nbsp;BOOL bFinished=find.FindFile(strName);<BR>&nbsp;&nbsp;while (bFinished)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp; &amp; nbsp ;&amp; nbsp ;&amp; nbsp ;&amp; nbsp ;<BR>&nbsp;&nbsp; bFinished=find.FindNextFile();<BR>&nbsp;&nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;<BR>&nbsp;&nbsp; if (!find.IsDots())<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp; i=i+1;<BR>&nbsp;&nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;<BR>&nbsp;&nbsp; strcpy(chTemp,find.GetFileName().GetBuffer(100));<BR>&nbsp;&nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;<BR>&nbsp;&nbsp; sprintf(chFile,"%s\\%s",strDir,chTemp);<BR>&nbsp;&nbsp; if(find.IsDirectory())<BR>&nbsp;&nbsp;&nbsp;&nbsp;FindAllFile(chFile);<BR>&nbsp;&nbsp; else<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; CListCtrl* pList=(CListCtrl*)GetDlgItem (IDC_LIST1);<BR>&nbsp;&nbsp;&nbsp;&nbsp; pList-&gt;InsertItem(i,chFile,i);<BR>&nbsp;&nbsp;&nbsp;&nbsp; pList-&gt;SetBkColor(RGB(255,255,255));<BR>&nbsp;&nbsp;&nbsp;&nbsp; pList-&gt;SetTextColor(RGB(0,0,255));<BR>&nbsp;&nbsp; }<BR> }<BR>}<BR> find.Close();<BR>}<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:bird 回复日期:2003-01-09 10:22:05
<br>内容:哈哈..........你把它删除了吧,那是网页中的回车标志!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:尹志安 回复日期:2003-01-09 16:57:09
<br>内容:谢谢了<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -