newuser11
asked on
Finding Files
My app is created with vc++ 6.0 win32 with MFC in a shared Dll.
I'm looking for an example code to look for files (ex:c:\test\*.txt -- look for all 'txt' files) and store them in an array and loop through the array.
Thanks.
ASKER
I have tried the CFileFind. Thanks. I have saved the files in a LPCTSTR array. When I tried to loop through, it's not displaying the files. what's wrong with the displaying?
CFileFind finder;
LPCTSTR szFileNames[255];
int i=0;
BOOL bWorking = finder.FindFile("c:\test\* .txt");
while (bWorking)
{
bWorking = finder.FindNextFile();
szFileNames[i] = finder.GetFileName();
cout << "File Name " << szFileNames[i] << endl;
i++;
}
for (int j=0; szFileNames[j] != NULL; j++)
{
cout << "For Loop " << &szFileNames[0] << endl;
}
Thanks.
CFileFind finder;
LPCTSTR szFileNames[255];
int i=0;
BOOL bWorking = finder.FindFile("c:\test\*
while (bWorking)
{
bWorking = finder.FindNextFile();
szFileNames[i] = finder.GetFileName();
cout << "File Name " << szFileNames[i] << endl;
i++;
}
for (int j=0; szFileNames[j] != NULL; j++)
{
cout << "For Loop " << &szFileNames[0] << endl;
}
Thanks.
ASKER
Increased points
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cfilefind.asp
for more info.