Exemplo n.º 1
0
void enumFile(const std::wstring& searchPath, EnumCallback callback, void* param)
{
	WIN32_FIND_DATA fd;
	HANDLE findFile = ::FindFirstFile((searchPath + L"*").c_str(), &fd);

	if (findFile == INVALID_HANDLE_VALUE)
	{
		::FindClose(findFile);
		return;
	}

	while (true)
	{
		if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
		{
			//file
			callback(searchPath + fd.cFileName, param);
		}
		else if (wcscmp(fd.cFileName, L".") != 0 && wcscmp(fd.cFileName, L"..")  != 0)
		{
			//folder
			enumFile(searchPath + fd.cFileName + L"/", callback, param);
		}
		if (!FindNextFile(findFile, &fd))
		{
			::FindClose(findFile);
			return;
		}
	}
}
Exemplo n.º 2
0
bool enumFile(const zp::String& searchPath, EnumCallback callback, void* param)
{
	WIN32_FIND_DATA fd;
	HANDLE findFile = ::FindFirstFile((searchPath + _T("*")).c_str(), &fd);

	if (findFile == INVALID_HANDLE_VALUE)
	{
		::FindClose(findFile);
		return true;
	}

	while (true)
	{
		if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
		{
			//file
			if (fd.nFileSizeHigh == 0)	//4g top
			{
				if (!callback(searchPath + fd.cFileName, fd.nFileSizeLow, param))
				{
					return false;
				}
			}
		}
		else if (Strcmp(fd.cFileName, _T(".")) != 0 && Strcmp(fd.cFileName, _T("..")) != 0)
		{
			//folder
			if (!enumFile(searchPath + fd.cFileName + DIR_STR, callback, param))
			{
				return false;
			}
		}
		if (!FindNextFile(findFile, &fd))
		{
			::FindClose(findFile);
			return true;
		}
	}
	::FindClose(findFile);
	return true;
}