16 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
18 IFileDialog *pfd = NULL;
20 CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileDialog,
21 reinterpret_cast<void **
>(&pfd));
22 std::string file_path_windows;
27 IShellItem *psiResult;
28 hr = pfd->GetResult(&psiResult);
32 psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
34 wcstombs(str, pszFilePath, 128);
35 file_path_windows = str;
37 CoTaskMemFree(pszFilePath);
44 return file_path_windows;
48 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
50 IFileDialog *pfd = NULL;
52 CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileDialog,
53 reinterpret_cast<void **
>(&pfd));
54 std::string folder_path_windows;
58 hr = pfd->GetOptions(&dwOptions);
60 hr = pfd->SetOptions(dwOptions | FOS_PICKFOLDERS);
64 IShellItem *psiResult;
65 hr = pfd->GetResult(&psiResult);
69 psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFolderPath);
71 wcstombs(str, pszFolderPath, 128);
72 folder_path_windows = str;
74 CoTaskMemFree(pszFolderPath);
83 return folder_path_windows;
87 const std::string &folder_path) {
88 std::vector<std::string> subdirectories;
89 WIN32_FIND_DATA findFileData;
90 HANDLE hFind = FindFirstFile((folder_path +
"\\*").c_str(), &findFileData);
91 if (hFind != INVALID_HANDLE_VALUE) {
93 if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
94 if (strcmp(findFileData.cFileName,
".") != 0 &&
95 strcmp(findFileData.cFileName,
"..") != 0) {
96 subdirectories.push_back(findFileData.cFileName);
99 }
while (FindNextFile(hFind, &findFileData) != 0);
102 return subdirectories;
106 const std::string &folder_path) {
107 std::vector<std::string> files;
108 WIN32_FIND_DATA findFileData;
109 HANDLE hFind = FindFirstFile((folder_path +
"\\*").c_str(), &findFileData);
110 if (hFind != INVALID_HANDLE_VALUE) {
112 if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
113 files.push_back(findFileData.cFileName);
115 }
while (FindNextFile(hFind, &findFileData) != 0);
121#elif defined(__linux__)
124 return "Linux: Open file dialog";
128 return "Linux: Open folder dialog";
132 const std::string& folder_path) {
133 return {
"Linux: Subdirectories in folder"};
137 const std::string& folder_path) {
138 return {
"Linux: Files in folder"};
static std::vector< std::string > GetSubdirectoriesInFolder(const std::string &folder_path)
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath.
static std::string ShowOpenFolderDialog()
ShowOpenFolderDialog opens a file dialog and returns the selected folder path.
static std::vector< std::string > GetFilesInFolder(const std::string &folder_path)