--- /dev/null
+\r
+#include "opencv2/contrib/contrib.hpp"\r
+\r
+#ifdef WIN32\r
+ #include <windows.h>\r
+ #include <tchar.h>\r
+#else\r
+ #include <direct.h>\r
+#endif\r
+\r
+namespace cv\r
+{\r
+ std::vector<std::string> Directory::GetListFiles( const string& directoryName, bool addPath )\r
+ {\r
+ std::vector<std::string> list;\r
+ list.clear();\r
+ std::string path = directoryName + "/*";\r
+ #ifdef WIN32\r
+ WIN32_FIND_DATA FindFileData;\r
+ HANDLE hFind;\r
+\r
+ hFind = FindFirstFile((LPCSTR)path.c_str(), &FindFileData);\r
+ if (hFind == INVALID_HANDLE_VALUE) \r
+ {\r
+ return list;\r
+ }\r
+ else\r
+ {\r
+ do\r
+ {\r
+ if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_NORMAL || \r
+ FindFileData.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE || \r
+ FindFileData.dwFileAttributes == FILE_ATTRIBUTE_HIDDEN || \r
+ FindFileData.dwFileAttributes == FILE_ATTRIBUTE_SYSTEM || \r
+ FindFileData.dwFileAttributes == FILE_ATTRIBUTE_READONLY)\r
+ {\r
+ if (addPath)\r
+ list.push_back(directoryName + "/" + FindFileData.cFileName);\r
+ else\r
+ list.push_back(FindFileData.cFileName);\r
+ }\r
+ } \r
+ while(FindNextFile(hFind, &FindFileData));\r
+ FindClose(hFind); \r
+ }\r
+ #else\r
+ DIR *dp;\r
+ struct dirent *dirp;\r
+ if((dp = opendir(directoryName.c_str())) == NULL) \r
+ { \r
+ return list;\r
+ }\r
+\r
+ while ((dirp = readdir(dp)) != NULL) \r
+ {\r
+ if (dirp->d_type == DT_REG)\r
+ list.push_back(static_cast<string>(dirp->d_name));\r
+ }\r
+ closedir(dp);\r
+ #endif\r
+\r
+ return list;\r
+ }\r
+\r
+ std::vector<std::string> Directory::GetListFolders( const string& directoryName, bool addPath )\r
+ {\r
+ std::vector<std::string> list;\r
+ std::string path = directoryName + "/*";\r
+ list.clear();\r
+ #ifdef WIN32\r
+ WIN32_FIND_DATA FindFileData;\r
+ HANDLE hFind;\r
+\r
+ hFind = FindFirstFile((LPCSTR)path.c_str(), &FindFileData);\r
+ if (hFind == INVALID_HANDLE_VALUE) \r
+ {\r
+ return list;\r
+ }\r
+ else\r
+ {\r
+ do\r
+ {\r
+ if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY && \r
+ strcmp(FindFileData.cFileName, ".") != 0 && \r
+ strcmp(FindFileData.cFileName, "..") != 0)\r
+ {\r
+ if (addPath)\r
+ list.push_back(directoryName + "/" + FindFileData.cFileName);\r
+ else\r
+ list.push_back(FindFileData.cFileName);\r
+ }\r
+ } \r
+ while(FindNextFile(hFind, &FindFileData));\r
+ FindClose(hFind); \r
+ }\r
+\r
+ #else\r
+ DIR *dp;\r
+ struct dirent *dirp;\r
+ if((dp = opendir(path.c_str())) == NULL) \r
+ { \r
+ return list;\r
+ }\r
+\r
+ while ((dirp = readdir(dp)) != NULL) \r
+ {\r
+ if (dirp->d_type == DT_DIR)\r
+ list.push_back(static_cast<string>(dirp->d_name));\r
+ }\r
+ closedir(dp);\r
+ #endif\r
+\r
+ return list;\r
+ }\r
+\r
+ std::vector<std::string> Directory::GetListFilesR ( const string& directoryName, bool addPath )\r
+ {\r
+ std::vector<std::string> list = Directory::GetListFiles(directoryName, addPath);\r
+\r
+ std::vector<std::string> dirs = Directory::GetListFolders(directoryName, addPath);\r
+\r
+ std::vector<std::string>::const_iterator it;\r
+ for (it = dirs.begin(); it != dirs.end(); ++it)\r
+ {\r
+ std::vector<std::string> cl = Directory::GetListFiles(*it, addPath);\r
+ list.insert(list.end(), cl.begin(), cl.end());\r
+ }\r
+\r
+ return list;\r
+ }\r
+\r
+}
\ No newline at end of file