遍历文件家中的文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 |
//调用下面函数或结构体所要包含的文件头 <span style= "background-color: rgb(255, 153, 0);" >#include <io.h> </span> void
Cdialog1Dlg::OnBnClickedOk() { CString sfile = "F:\\SQLyaog\\SQLyog Trial\\*.exe" ; //文件的路径 struct
_finddata_t
c_file; //_finddata_t结构体包含文件的文件名,大小最后一次访问修改时间等 long
hfile; //不能写成if(hfile = _findfirst(LPCSTR(sfile),&c_file) == -1L)<span style="background-color: rgb(255, 102, 0);">因为==的优先级要比=高 </span> //搜索与指定文件名称或路径匹配的第一个实例,若成功返回第一个实例句柄 //否则返回-1L if ((hfile = <span style= "background-color: rgb(255, 102, 0);" >_findfirst</span>( LPCSTR (sfile),&c_file)) == -1L) // { ::AfxMessageBox( "No PE file in current directory" ); } else { do { AfxMessageBox(( LPCSTR )c_file.name); //输出检索到的符合要求的文件名 } while <span style= "background-color: rgb(255, 102, 0);" >(_findnext</span>(hfile,&c_file) <span style= "background-color: rgb(255, 102, 0);" >== 0</span>); //搜索与_findfirst函数提供的文件名 //相匹配的下一个实例,若成功返回0,否则返回-1. } _findclose(hfile<span style= "background-color: rgb(255, 102, 0);" >); //释放句柄。 </span> CDialogEx::OnOK(); } |
缺点:加入此文件还含有文件夹,此方法没能很好的解决此子文件夹里的和服要求的文件。
原文:http://www.cnblogs.com/jiaoluo/p/3521432.html