void Path::GetAllFiles(std::vector<std::string> &files, const std::string &path, const std::string &filter) { Directory* pDir = new Directory(); DirEnumerator* pDirEnum; result r = pDir->Construct(path.c_str()); if (r != E_SUCCESS) { AppLog(GetErrorMessage(r)); delete pDir; return; } pDirEnum = pDir->ReadN(); while (pDirEnum->MoveNext() == E_SUCCESS) { DirEntry entry = pDirEnum->GetCurrentDirEntry(); if (entry.IsDirectory()) continue; Path fileName(StringUtils::ToNarrow(entry.GetName().GetPointer())); if (fileName.GetExt() == filter.substr(filter.size() - 3)) { files.push_back(fileName.GetFilenameExt()); } } delete pDir; delete pDirEnum; }
bool BadaFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { AppAssert(isDirectory()); bool result = false; if (_isVirtualDir && mode != Common::FSNode::kListFilesOnly) { // present well known BADA file system areas if (_path == PATH_ROOT) { myList.push_back(new BadaFilesystemNode(PATH_HOME)); myList.push_back(new BadaFilesystemNode(PATH_HOME_EXT)); myList.push_back(new BadaFilesystemNode(PATH_MEDIA)); myList.push_back(new BadaFilesystemNode(PATH_CARD)); result = true; // no more entries } else if (_path == PATH_CARD) { myList.push_back(new BadaFilesystemNode(PATH_CARD_MEDIA)); result = true; // no more entries } else if (_path == PATH_HOME) { // ensure share path is always included myList.push_back(new BadaFilesystemNode(PATH_HOME_SHARE)); myList.push_back(new BadaFilesystemNode(PATH_HOME_SHARE2)); } } if (!result) { DirEnumerator *pDirEnum = 0; Directory *pDir = new Directory(); // open directory if (IsFailed(pDir->Construct(_unicodePath))) { AppLog("Failed to open directory: %S", _unicodePath.GetPointer()); } else { // read all directory entries pDirEnum = pDir->ReadN(); if (pDirEnum) { result = true; } // loop through all directory entries while (pDirEnum && pDirEnum->MoveNext() == E_SUCCESS) { DirEntry dirEntry = pDirEnum->GetCurrentDirEntry(); // skip 'invisible' files if necessary Osp::Base::String fileName = dirEntry.GetName(); if (fileName[0] == '.' && !hidden) { continue; } // skip '.' and '..' to avoid cycles if (fileName == L"." || fileName == L"..") { continue; } // Honor the chosen mode if ((mode == Common::FSNode::kListFilesOnly && dirEntry.IsDirectory()) || (mode == Common::FSNode::kListDirectoriesOnly && !dirEntry.IsDirectory())) { continue; } myList.push_back(new BadaFilesystemNode(_path, fromString(fileName))); } } // cleanup if (pDirEnum) { delete pDirEnum; } // close the opened directory if (pDir) { delete pDir; } } return result; }