#include <stdio.h>
#include <dirent.h>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
using namespace std;
vector<string> filenames;
vector<string> oppFilenames;
int customFilter(const struct dirent *pDir) {
string nameStr(pDir->d_name);
string prefix = nameStr.substr(nameStr.rfind(".") + 1);
if (!strcmp(prefix.c_str(), "dat")) {
// 非零为保留 - 不滤掉
return 1;
}
// 零为过滤掉 - 过滤掉
return 0;
}
int main() {
struct dirent **namelist;
int n;
n = scandir("COMTRADE", &namelist, customFilter, versionsort);
if (n < 0) {
perror("scandir");
} else {
for (int i = n - 1; i >= 0; i--) {
filenames.push_back(namelist[i]->d_name);
free(namelist[i]);
}
free(namelist);
for (int j = 0; j < filenames.size(); j++) {
cout << filenames[j] << endl;
}
}
return 0;
}
#include <dirent.h>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
using namespace std;
vector<string> filenames;
vector<string> oppFilenames;
int customFilter(const struct dirent *pDir) {
string nameStr(pDir->d_name);
string prefix = nameStr.substr(nameStr.rfind(".") + 1);
if (!strcmp(prefix.c_str(), "dat")) {
// 非零为保留 - 不滤掉
return 1;
}
// 零为过滤掉 - 过滤掉
return 0;
}
int main() {
struct dirent **namelist;
int n;
n = scandir("COMTRADE", &namelist, customFilter, versionsort);
if (n < 0) {
perror("scandir");
} else {
for (int i = n - 1; i >= 0; i--) {
filenames.push_back(namelist[i]->d_name);
free(namelist[i]);
}
free(namelist);
for (int j = 0; j < filenames.size(); j++) {
cout << filenames[j] << endl;
}
}
return 0;
}