afx.h
----------------
Win32API中类似的函数有FindFirstFile,定义在燃丛Winbase.h中。使用时需要乎销包含以下头文件:
windows.h
给你一段代码:
/*
Path:你需要搜索的文件夹路径,可以是C:\\,代表C盘根目录,
type:搜索文件类型此颂扩展名,比如avi,MP3等
返回值:所有查找到的文件名list容器中,你可以稍加修改返回值为文件的绝对路径等。
提示:记得添加相应头文件:
*/
list<string>GetFileNameInOneDir(string Path, string Type)
{
list<string>ListName
_finddata_t file
long longf
string PathTemp=Path
PathTemp+="\\*.*"
string FullPath=Path
FullPath+="\\"
if((longf = _findfirst(PathTemp.c_str(), &file))==-1l)
{
AfxMessageBox("文件夹粗扒弯没有找到!")
//cout<<"岩闷文件夹没有找到!"<<endl
}
else
{
string tempName
while( _findnext( longf, &file ) == 0 )
{
tempName = ""
tempName = file.name
if (tempName == "..")
{
continue
}
FullPath+=file.name
if(strcmp(Type.c_str(),PathFindExtension(FullPath.c_str())+1)==0)
ListName.push_back(file.name)
}
}
_findclose(longf)
return ListName
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)