The functions FindFirstFile() and FindNextFile() will iterate the all the files and sub-directories. For each file they return a structure that contains the filename, attributes, size and other data. Check the file's attributes to see that it is a normal file and, if it is, your program can open and edit it.
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Thanks Ancient Dragon for your answer. As for FindFirstFile() and FindNextFile(), could you please tell me which C++ library should be included in order for the two functions to be available? I was not able to find them in C++ Builder but that doesn't mean they do not exist at all.
Thanks again!
Does it support
If not, dev-cpp from bloodshed definitely does.
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
HANDLE hFind;
WIN32_FIND_DATA FindData;
int ErrorCode;
BOOL Continue = TRUE;
cout << "A decent FindFirst/Next demo." << endl << endl;
hFind = FindFirstFile("C:\\*.txt", &FindData);
if(hFind == INVALID_HANDLE_VALUE)
{
ErrorCode = GetLastError();
if (ErrorCode == ERROR_FILE_NOT_FOUND)
{
cout << "There are no files matching that path/mask\n" << endl;
}
else
{
cout << "FindFirstFile() returned error code " << ErrorCode << endl;
}
Continue = FALSE;
}
else
{
cout << FindData.cFileName << endl;
}
if (Continue)
{
while (FindNextFile(hFind, &FindData))
{
cout << FindData.cFileName << endl;
}
ErrorCode = GetLastError();
if (ErrorCode == ERROR_NO_MORE_FILES)
{
cout << endl << "All files logged." << endl;
}
else
{
cout << "FindNextFile() returned error code " << ErrorCode << endl;
}
if (!FindClose(hFind))
{
ErrorCode = GetLastError();
cout << "FindClose() returned error code " << ErrorCode << endl;
}
}
cin.get();
}
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Thanks Ancient Dragon for your answer. As for FindFirstFile() and FindNextFile(), could you please tell me which C++ library should be included in order for the two functions to be available? I was not able to find them in C++ Builder but that doesn't mean they do not exist at all.
Thanks again!
You will also need to read the Microsoft docs for those functions -- here
Ancient Dragon
Retired & Loving It
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343