Beispiel #1
0
std::vector<std::wstring> GetFileList(const std::wstring& pattern, const bool fullPaths)
{
	const std::wstring directory = (fullPaths ? GetDirPart(pattern) : L"");

	// may not pass an empty string to FindFirstFileEx
	UIETWASSERT(pattern.length() > 0);

	// string passed to FindFirstFileEx must not end in a backslash
	UIETWASSERT(pattern.back() != L'\\');

	WIN32_FIND_DATA findData;
	HANDLE hFindFile = ::FindFirstFileExW(pattern.c_str(), FindExInfoBasic,
				&findData, FindExSearchNameMatch, NULL, 0);

	std::vector<std::wstring> result;
	if (hFindFile == INVALID_HANDLE_VALUE)
	{
		// If there are NO matching files, then FindFirstFileExW returns
		// INVALID_HANDLE_VALUE and the last error is ERROR_FILE_NOT_FOUND.
		UIETWASSERT(::GetLastError() == ERROR_FILE_NOT_FOUND);
		return result;
	}
	do
	{
		result.emplace_back(directory + findData.cFileName);
	} while (::FindNextFileW(hFindFile, &findData));

	UIETWASSERT(::GetLastError() == ERROR_NO_MORE_FILES);
	ATLVERIFY(::FindClose(hFindFile));
	return result;
}
Beispiel #2
0
std::vector<std::wstring> GetFileList(const std::wstring& pattern, bool fullPaths)
{
	std::wstring directory;
	if (fullPaths)
		directory = GetDirPart(pattern);
	WIN32_FIND_DATA findData;
	HANDLE hFindFile = FindFirstFileEx(pattern.c_str(), FindExInfoStandard,
				&findData, FindExSearchNameMatch, NULL, 0);

	std::vector<std::wstring> result;
	if (hFindFile != INVALID_HANDLE_VALUE)
	{
		do
		{
			result.emplace_back(directory + findData.cFileName);
		} while (FindNextFile(hFindFile, &findData));

		FindClose(hFindFile);
	}

	return result;
}