Yes, "sometimes" the API consumer just wants to match XML files. For example, when creating one of these silly file dialogs that never show what I'm looking for.
> Why do you consider this a poor API and what would you consider a better API?
POSIX gets that just right. No fuss, expose the technical reality in straightforward abstractions. You call opendir() and get an DIR* handle (representing an open directory). Then you call readdir() with that handle in a loop to get all the files in a directory.
I'm not saying I'm strictly against bells and whistles, but often these only work for a first prototype, and if API designers don't offer a straightforward way so I can simply do what needs to be done, they really failed at their job.
I will concede that I've often wondered why the file mask was not a separate parameter, so that it could be NULL if you just wanted to iterate over all the files.
As for "sometimes" wanting to filter, the majority of the times I use FindFirstFile, I do with a mask different from "all entries". Guess it depends what kind of programs one writes.
It certainly is a good thing that the capability is there, as it leads to consistency. But I agree it would be better if they had split the mask into a separate parameter.
> POSIX gets that just right.
It certainly is cleaner to separate the two. Though I've never had the need to split the code opening vs iterating, so at least for me, the practical difference is minor.
Why not FindFile()?
As far as I can see, either you have some separate call to initialize the find handle (just like FindFirstFile does), or you pass the directory/filename mask redundantly over and over again, introducing the potential for suddenly calling it with an already initialized find handle but with a different directory.
There are a few library calls that have a cousin with an _r suffix in POSIX, but these are not system interfacing calls. Just don't use them if they don't match your requirements. Most of them aren't even non-reentrant or thread-unsafe, but simply lack an additional parameter for some use cases (the use cases mostly come when you program in object-oriented style).
The one offender (not a system call, either) that I know from the top of my head is strtok() which is of course terrible, but why would you use it?
Getting API design right is _hard_.
Neither are most Windows functions. FindFirstFile, for example, is defined in kernel32.dll, and calls through to ntdll.dll, and eventually makes system calls such as NtOpenDirectoryObject and NtQueryDirectoryObject.
What IMO matters is the usability of the stable API. It doesn’t matter whether that is the kernel interface or not.
Then there's `wordexp()` and `wordfree()`. The first takes a file glob (file pattern?) and returns an array of filenames matching the pattern. Any memory allocated by `wordexp()` is freed by calling `wordfree()`.
Both have their uses.
Your reply here could of been a great reply to the original question.
I then assumed you proposed something similar with your FindFile call, and I didn't and still don't see how to do that in a clean way, hence asking how you would imagine it working.
In a reply the OP clarified that it was the fact that FindFirstFile does two things (initializing the handle, and getting the first result if any), rather than cleanly separating the handle initialization from getting the results. This is different, and a point I can agree with.
Edit: I should clarify. It was a low effort question to another low effort question. I should state that I have no experience with the API in question. I was just asking a question of the difference between the two, and the poster above me answer in another reply that the answer is that FindFirstFile is used to initialize / reset the query, where FindNextFile is use to continue the query.
To further answer the question I was replying to above, I think another function that could be paired with a hypothetical FindFile would be a method to initialize the query.
I do not know what would be a better API.
This is the obvious and correct way to do it, and it's the way it's done in POSIX with opendir() / readdir().
Because sometimes you just want get all the XML files in a directory, and it's nice to not have to filter yourself.
> why do I need to find the first file with FindFirstFile() and all the remaining files with FindNextFile()?
Why do you consider this a poor API and what would you consider a better API?