黄靖这个名字怎么样:C++读取某一目录下的所有文件名

来源:百度文库 编辑:九乡新闻网 时间:2024/07/14 16:13:04
#include 
#include
using namespace std;

void main()
{
_finddata_t file;
long lf;
//修改这里选择路径和要查找的文件类型
if((lf = _findfirst("E:\\msdn\\*.txt",&file))==-1l)
//_findfirst返回的是long型;long __cdecl _findfirst(const char *, struct _finddata_t *)
cout<<"文件没有找到!\n";
else
{
cout<<"\n文件列表:\n";
do{
cout< if(file.attrib == _A_NORMAL)cout<<" 普通文件 ";
else if(file.attrib == _A_RDONLY)cout<<" 只读文件 ";
else if(file.attrib == _A_HIDDEN )cout<<" 隐藏文件 ";
else if(file.attrib == _A_SYSTEM )cout<<" 系统文件 ";
else if(file.attrib == _A_SUBDIR)cout<<" 子目录 ";
else cout<<" 存档文件 ";
cout< } while( _findnext( lf, &file ) == 0 );
//int __cdecl _findnext(long, struct _finddata_t *);如果找到下个文件的名字成功的话就返回0,否则返回-1

}
_findclose(lf);
}