Created
May 3, 2018 11:45
-
-
Save YHaruoka/b2ee6ff063e22eb9f3853a5597c72caf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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