2 ms·
FindFile, FindNextFile are an iterator pattern. In C++, you have auto iterator = container.begin(); while(iterator != container.end()){ ++iterat
by RcouF1uZ4gsC 8y ago
FindFile, FindNextFile are an iterator pattern.
In C++, you have
auto iterator = container.begin();
while(iterator != container.end()){
++iterator;
}
In Java you have
Iterator<String> iterator = container.iterator();
while(iterator.hasNext()) {
iterator.next();
}
Similarly with FindFile you have (leaving off some parameters)
auto handle = FindFirstFile();
while(FindNextFile(handle)){}
CloseFile(handle);
Separating the creation of the iterator from advancing the iterator is a good thing.
- asveikau 8y agoYou are correct. The actual pattern you want to use in practice with this API is more of a do ... while: WIN32_FIND_DATA data; HANDLE handle; handle = FindFirstFile(str, &data); // TODO - error check do { // TODO: process "data" which is a file. } while (FindNextFile(handle, &data)); FindClose(handle); So the loop body is the same for the "first" and "next" files.