//system
#include <iostream>
#include <filesystem>
#include <fstream>
using namespace std;
inline bool endsWith(const string& str, const string& suffix)
{
if (str.size() < suffix.size()) {
return false;
}
auto tstr = str.substr(str.size() - suffix.size());
return tstr.compare(suffix) == 0;
}
int main()
{
vector<string> inputFiles;
string tempFolder = "C:\Test";
fs::path p1(tempFolder);
//检查文件夹是否存在
if (fs::exists(p1))
{
for (const auto& entry : fs::directory_iterator(tempFolder))
{
//获取文件
string filename = entry.path().filename().string();
//判断后缀
if (endsWith(filename, "txt"))
{
inputFiles.push_back(filename);
}
}
}
}
C++11 获取文件夹下指定后缀文件
最新推荐文章于 2024-01-23 23:12:37 发布