Member 7766180 wrote:
I want it to return 0 if no files are found.
This code already ensure 0 is returned when no files are returned.
if(h == INVALID_HANDLE_VALUE)
{
return 0; }
You should change your
main()
to check for the number of found files before using the
map
in the
for
loop.
Try this:
GetFileList(L"C:\\Users\\DS\\Downloads\\*.pdf", map);
GetFileList(L"C:\\Users\\DS\\Downloads\\*.txt", map);
GetFileList(L"C:\\Users\\DS\\Downloads\\*.jpg", map);
if( map.size() > 0 )
{
for(std::map::const_iterator it = map.begin(); it != map.end(); ++it)
{
....
}
}
Also you need to close the find handle before the
GetFileList
functions returns.
Add
FindClose(h);
before
return map.size();