Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <Windows.h>
#include <stdexcept>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// 入力フォルダ名の指定
string INPUT_FOLDER_NAME = "./input_image/";
// INPUT_FOLDER_NAMEのフォルダ内にある画像名を取得する
vector<string> getImageName(string dir_name) {
HANDLE hFind;
WIN32_FIND_DATA win32fd;
std::vector<std::string> file_names;
// png,jpg,bmpの拡張子のファイルのみを読み込む
std::string extension[3] = {"png" ,"jpg", "bmp"};
for (int i = 0; i < 3; i++) {
string search_name = dir_name + "*." + extension[i];
hFind = FindFirstFile(search_name.c_str(), &win32fd);
if (hFind == INVALID_HANDLE_VALUE) {
continue;
}
do {
if (win32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
}
else {
file_names.push_back(win32fd.cFileName);
}
} while (FindNextFile(hFind, &win32fd));
FindClose(hFind);
}
return file_names;
}
int main(void) {
// ファイル内の画像名の取得
vector<string> file_names = getImageName(INPUT_FOLDER_NAME);
// 表示部分
for (auto f : file_names) {
cout << f << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment