30 #include <sys/types.h> 31 #include <sys/param.h> 47 bool sortCallback(
const std::string & a,
const std::string & b)
52 int sortCallback(
const struct dirent ** a,
const struct dirent ** b)
108 std::string lastName;
109 bool endOfDir =
false;
122 WIN32_FIND_DATA fileInformation;
124 wchar_t * pathAll = createWCharFromChar((
path_+
"\\*").c_str());
125 HANDLE hFile = ::FindFirstFile(pathAll, &fileInformation);
128 HANDLE hFile = ::FindFirstFile((
path_+
"\\*").c_str(), &fileInformation);
130 if(hFile != INVALID_HANDLE_VALUE)
135 char * fileName = createCharFromWChar(fileInformation.cFileName);
139 fileNames_.push_back(fileInformation.cFileName);
141 }
while(::FindNextFile(hFile, &fileInformation) == TRUE);
144 std::sort(vFileNames.begin(), vFileNames.end(),
sortCallback);
149 struct dirent ** nameList = 0;
151 if(nameList && nameListSize>0)
153 for (
int i=0;i<nameListSize;++i)
163 std::list<std::string>::iterator iter =
fileNames_.begin();
169 iter->compare(
".") != 0 &&
170 iter->compare(
"..") != 0)
192 if(!lastName.empty())
197 if(lastName.compare(*iter) == 0)
204 if(endOfDir && found)
223 std::string fileName;
234 std::string filePath;
254 wchar_t * wDirPath = createWCharFromChar(dirPath.c_str());
255 DWORD dwAttrib = GetFileAttributes(wDirPath);
258 DWORD dwAttrib = GetFileAttributes(dirPath.c_str());
260 r = (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
263 if((dp = opendir(dirPath.c_str())) !=
NULL)
275 std::string dir = filePath;
276 int i=(int)dir.size()-1;
279 if(dir[i] ==
'/' || dir[i] ==
'\\')
284 while(i>=0 && (dir[i] ==
'/' || dir[i] ==
'\\'))
315 buffer = _getcwd(
NULL, 0);
317 buffer = getcwd(
NULL, MAXPATHLEN);
324 if(trailingSeparator)
337 status = _mkdir(dirPath.c_str());
339 status = mkdir(dirPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
348 status = _rmdir(dirPath.c_str());
350 status = rmdir(dirPath.c_str());
360 wchar_t wProfilePath[250];
361 ExpandEnvironmentStrings(L
"%userprofile%",wProfilePath,250);
362 char * profilePath = createCharFromWChar(wProfilePath);
364 delete [] profilePath;
366 char profilePath[250];
367 ExpandEnvironmentStrings(
"%userprofile%",profilePath,250);
371 char * pathstr = getenv(
"HOME");
378 struct passwd *pw = getpwuid(getuid());
384 UFATAL(
"Environment variable HOME is not set, cannot get home directory! Please set HOME environment variable to a valid directory.");
static std::string homeDir()
int sortCallback(const dirent **a, const dirent **b)
static bool makeDir(const std::string &dirPath)
int uStrNumCmp(const std::string &a, const std::string &b)
std::list< std::string > fileNames_
static std::string getDir(const std::string &filePath)
UDirectory(const std::string &path="", const std::string &extensions="")
static std::string separator()
UDirectory & operator=(const UDirectory &dir)
Some conversion functions.
std::string getExtension()
Wrappers of STL for convenient functions.
std::list< std::string > uSplit(const std::string &str, char separator=' ')
std::vector< std::string > extensions_
static std::string currentDir(bool trailingSeparator=false)
void setPath(const std::string &path, const std::string &extensions="")
std::list< std::string >::iterator iFileName_
std::list< V > uVectorToList(const std::vector< V > &v)
std::vector< V > uListToVector(const std::list< V > &list)
std::string getNextFilePath()
std::string getNextFileName()
static bool removeDir(const std::string &dirPath)
ULogger class and convenient macros.
static bool exists(const std::string &dirPath)