C++程式碼如下:
#include <iostream>
#include <filesystem>
#include <string>
using namespace std;
using namespace std::filesystem;
int main()
try
{
cout << "使用filesystem要先調專案屬性到C++17!!\n";
cout << "如果不知本專案所在path就試一下下面:\n";
path basePath = current_path();
cout <<basePath << endl;
if (!exists(path("images"))) {
create_directory("images");
cout << "mkdir images\n";
}
int i = 0;
for (const auto& entry : recursive_directory_iterator("D:\\cpp\\test_cv_dnn"))
{
if (entry.is_regular_file())
{
path ff = entry.path();
string fn = entry.path().string();
int pos = -1;
if ((pos = fn.rfind(".jpg")) == fn.length() - 4) {
cout << "pos=" << pos << "\t" << fn << endl;
string toFile ="images\\"+ to_string(i) + ".jpg";
copy_file(ff, path(toFile), copy_options::overwrite_existing);
cout << "已經copy圖檔" << fn << "到" << toFile << endl;
i++;
}
}
}
return 0;
}
catch (exception& e) {
cerr << e.what();
return 1;
}
沒有留言:
張貼留言
HTML 編輯器