[root@localhost 桌面]# g++ temp.cpp -o temp.exe
[root@localhost 桌面]# ./temp.exe
/etc/nginx/html/database/processTemplate/
a
a
2
HeatingRepair.xml
TestNotePad.xml
[root@localhost 桌面]#
temp.cpp
-
//indent -npro -kr -i8 -ts8 -sob -l280 -ss -ncs -cp1 *.c *.h *.cpp *.hpp
-
//indent -npro -kr -i8 -ts8 -sob -l280 -ss -ncs -cp1 *
-
-
#include <string.h>
-
#include <iostream>
-
#include <vector>
-
#include <string>
-
#include <dirent.h>
-
using namespace std;
-
-
typedef vector < string > FilesList;
-
void ls(const string & sDir, FilesList & files, const char *acExtension);
-
-
int main()
-
{
-
FilesList files;
-
ls("/etc/nginx/html/database/processTemplate/", files, ".xml");
-
-
cout << files.size() << endl;
-
-
for (int i = 0; i < files.size(); i++) //ztg add
-
{
-
cout << files[i] << endl;
-
}
-
return 0;
-
}
-
-
void ls(const string & sDir, FilesList & files, const char *acExtension)
-
{
-
int return_code;
-
DIR *dir;
-
struct dirent entry;
-
struct dirent *res;
-
-
char *sourceDir = new char[sDir.size() + 4];
-
strcpy(sourceDir, sDir.c_str());
-
//strcat(sourceDir, "\\*");
-
-
cout << sourceDir << endl;
-
-
if ((dir = opendir(sourceDir)) != NULL) { //open dir
-
for (return_code = readdir_r(dir, &entry, &res); res != NULL && return_code == 0; return_code = readdir_r(dir, &entry, &res)) {
-
if (entry.d_type != DT_DIR) { //save to files
-
//doc_list.push_back(string(entry.d_name));
-
cout << "a" << endl;
-
if ((acExtension != NULL)) {
-
-
string sFile = entry.d_name;
-
-
int iPos = sFile.find_last_of(".");
-
if ((iPos == string::npos) || (strcmp(acExtension, sFile.substr(iPos).c_str())))
-
continue;
-
}
-
-
files.push_back(entry.d_name);
-
}
-
}
-
closedir(dir); //close dir
-
}
-
}
阅读(2614) | 评论(0) | 转发(0) |