69 int GetFileNameByExt(char* zsDir, char* zsExt, vector& vFileList)
70 {
71
string zsLowerExt = zsExt;
72
struct dirent *pENT = NULL;
73
DIR *pDir;
74
struct stat stStat;
75
76
transform(zsLowerExt.begin(), zsLowerExt.end(), zsLowerExt.begin(), ::tolower);
77
78
pDir = opendir(zsDir);
79
if(pDir == NULL)
80
return 0;
81
82
pENT = readdir(pDir);
83
while(pENT != NULL)
84
{
85
string zsFile = zsDir;
86
zsFile += pENT->d_name;
87
88
lstat(zsFile.c_str(), &stStat);
89
90
91
92
if(S_ISDIR(stStat.st_mode) )
93
{
94
}
95
else
96
{
97
size_t pos = zsFile.find_last_of('.');
98
if(pos == zsFile.npos)
99
{
100
continue;
101
}
102
103
104
string zsExt = zsFile.substr(pos + 1);
105
transform(zsExt.begin(), zsExt.end(), zsExt.begin(), ::tolower);
106
107
if(zsExt == zsLowerExt)
108
{
109
vFileList.push_back(zsFile);
110
}
111
112
113
}
114
115
116
pENT = readdir(pDir);
117
}
118
119
return vFileList.size();
}