PF_API 0.52
|
00001 00002 // Copyright (C) 2010 Dylan Blair 00003 // 00004 // email: dblair@alumni.cs.utexas.edu 00005 // 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License, or (at your option) any later version. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 #ifndef UDIR_H 00022 #define UDIR_H 00023 00024 #include <list> 00025 #include <string> 00026 00027 #ifdef _WIN32 00028 #include <windows.h> 00029 00030 namespace OpenSkyNet { 00031 namespace Utils { 00032 inline void GetFileNamesInDir(const std::string& dir_, std::list<std::string>& fileNames_) { 00033 fileNames_.clear(); 00034 00035 WIN32_FIND_DATA findData; 00036 HANDLE hFind = FindFirstFile((dir_ + "*").c_str(), &findData); 00037 if (hFind != INVALID_HANDLE_VALUE) { 00038 std::string fileName(findData.cFileName); 00039 if (fileName != "." && fileName != "..") 00040 fileNames_.push_back(fileName); 00041 while (FindNextFile(hFind, &findData)) { 00042 std::string fileName(findData.cFileName); 00043 if (fileName != "." && fileName != "..") 00044 fileNames_.push_back(fileName); 00045 } 00046 FindClose(hFind); 00047 } 00048 } 00049 } 00050 } 00051 #else 00052 #include <dirent.h> 00053 00054 namespace OpenSkyNet { 00055 namespace Utils { 00056 inline void GetFileNamesInDir(const std::string& dir_, std::list<std::string>& fileNames_) { 00057 fileNames_.clear(); 00058 00059 dirent** nameList; 00060 int numNames = scandir(dir_.c_str(), &nameList, 0, alphasort); 00061 if (numNames > 0) { 00062 for (int i = 0; i < numNames; ++i) { 00063 std::string fileName(nameList[i]->d_name); 00064 if (fileName != "." && fileName != "..") 00065 fileNames_.push_back(fileName); 00066 free(nameList[i]); 00067 } 00068 free(nameList); 00069 } 00070 } 00071 } 00072 } 00073 #endif 00074 00075 #endif //UDIR_H