00001
00002
00003
00004
00005
00006 #ifndef Impala_Util_DirImageFileNames_h
00007 #define Impala_Util_DirImageFileNames_h
00008
00009 #include <string>
00010 #include <vector>
00011 #include "Basis/FileName.h"
00012
00013 #ifndef WIN32
00014 #include <dirent.h>
00015 #endif
00016
00017 namespace Impala {
00018 namespace Util {
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifdef WIN32
00036
00037 void DirImageFileNames(std::string dirName, std::vector<std::string*>& fNames)
00038 {
00039 WIN32_FIND_DATA FindFileData;
00040 HANDLE hFind = INVALID_HANDLE_VALUE;
00041 std::string* fileName;
00042
00043 fNames.clear();
00044 dirName += "/*";
00045
00046 hFind = FindFirstFile(dirName.c_str(), &FindFileData);
00047 if(hFind == INVALID_HANDLE_VALUE)
00048 return;
00049
00050 do {
00051 std::string ext = FileNameExt(FindFileData.cFileName,true);
00052 if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "raw")
00053 {
00054 fileName = new std::string(FindFileData.cFileName);
00055 fNames.push_back(fileName);
00056 }
00057 } while(FindNextFile(hFind, &FindFileData) != 0);
00058
00059 FindClose(hFind);
00060 }
00061
00062 #else
00063
00064 void DirImageFileNames(std::string dirName, std::vector<std::string*>& fNames)
00065 {
00066 DIR *dp;
00067 struct dirent *dirp;
00068 std::string* fileNameP;
00069
00070 fNames.clear();
00071
00072 if((dp = opendir(dirName.c_str())) == NULL) {
00073 return;
00074 }
00075
00076
00077 while ((dirp = readdir(dp)) != NULL) {
00078 std::string fileName = std::string(dirp->d_name);
00079 std::string ext = FileNameExt(fileName,true);
00080 if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "raw")
00081 {
00082 fileNameP = new std::string(fileName);
00083 fNames.push_back(fileNameP);
00084 }
00085 }
00086 closedir(dp);
00087 return;
00088 }
00089
00090 #endif
00091
00092 }
00093 }
00094 #endif