S32 LLDir::deleteFilesInDir(const std::string &dirname, const std::string &mask) { S32 count = 0; std::string filename; std::string fullpath; S32 result; while (getNextFileInDir(dirname, mask, filename, FALSE)) { if ((filename == ".") || (filename == "..")) { // skipping directory traversal filenames count++; continue; } fullpath = dirname; fullpath += getDirDelimiter(); fullpath += filename; S32 retry_count = 0; while (retry_count < 5) { if (0 != LLFile::remove(fullpath)) { result = errno; llwarns << "Problem removing " << fullpath << " - errorcode: " << result << " attempt " << retry_count << llendl; ms_sleep(1000); } else { if (retry_count) { llwarns << "Successfully removed " << fullpath << llendl; } break; } retry_count++; } count++; } return count; }
BOOL LLDir_Win32::getNextFileInDir(const llutf16string &dirname, const std::string &mask, std::string &fname, BOOL wrap) { WIN32_FIND_DATAW FileData; fname = ""; llutf16string pathname = dirname; pathname += utf8str_to_utf16str(mask); if (pathname != mCurrentDir) { // different dir specified, close old search if (mCurrentDir[0]) { FindClose(mDirSearch_h); } mCurrentDir = pathname; // and open new one // Check error opening Directory structure if ((mDirSearch_h = FindFirstFile(pathname.c_str(), &FileData)) == INVALID_HANDLE_VALUE) { // llinfos << "Unable to locate first file" << llendl; return(FALSE); } } else // get next file in list { // Find next entry if (!FindNextFile(mDirSearch_h, &FileData)) { if (GetLastError() == ERROR_NO_MORE_FILES) { // No more files, so reset to beginning of directory FindClose(mDirSearch_h); mCurrentDir[0] = NULL; if (wrap) { return(getNextFileInDir(pathname,"",fname,TRUE)); } else { fname[0] = 0; return(FALSE); } } else { // Error // llinfos << "Unable to locate next file" << llendl; return(FALSE); } } } // convert from TCHAR to char fname = utf16str_to_utf8str(FileData.cFileName); // fname now first name in list return(TRUE); }
// get the next file in the directory // automatically wrap if we've hit the end BOOL LLDir_Win32::getNextFileInDir(const std::string &dirname, const std::string &mask, std::string &fname, BOOL wrap) { llutf16string dirnamew = utf8str_to_utf16str(dirname); return getNextFileInDir(dirnamew, mask, fname, wrap); }