Learn when you want, where you want with convenient online training courses. Sign up now!
[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
int main ()
// defines the stucture for find file at WINAPI
// the first call may fail and return INVALID_HANDLE_VALUE
// what is -1 casted to a HANDLE
HANDLE hFind = FindFirstFile("c:\\path\\*.txt"),&fd);
// in this case GetLastError will give a specific error
// check winerror.h for further analysis
// error 2 means file not found
// error 3 means folder not found
// error 5 means access denied
if (hFind == INVALID_HANDLE_VALUE)
// you can collect the filenames here in the loop
// directories would have the directory flag as attribute
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
std::cout << "File: " << fd.cFileName << std::endl;
while (FindNextFile(hFind, &fd) != NULL);
// the loop should end with 'no more files'
if (GetLastError() != ERROR_NO_MORE_FILES)
Open in new window
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.