Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file counting

Status
Not open for further replies.

ravenspawn

Technical User
May 3, 2001
13
0
0
US
How do I count files in a directory yet not using the LP_win32_data type?
 
Hi ravenspawn.

Here is some code to list the contents of a directory
under Windows.I have tested this for winnt 4.0.

Hope this answers your other query also.

Best Regards,
abp :cool:

#include <windows.h>
#include <stdio.h>
#include <iostream.h>

#ifdef _UNICODE
#undef _UNICODE
#endif

#define BUFFLEN 100

int main()
{
LPCTSTR dirName= &quot;<your directory path here>&quot;;
char srchStr[BUFFLEN];
char fileName[BUFFLEN];
WIN32_FIND_DATA* lpFileData;
HANDLE hFile;

sprintf(srchStr,&quot;%s/*.*&quot;, dirName);

lpFileData = new WIN32_FIND_DATA;

/* Open the directory */
hFile = ::FindFirstFile((LPCTSTR)srchStr, lpFileData);

if (hFile == INVALID_HANDLE_VALUE)
return 0;

// lpFileData = NULL;

while :):FindNextFile(hFile, lpFileData))
{
/* Get full path of file to print */
sprintf(fileName, &quot;%s%s&quot;, dirName, lpFileData->cFileName);
cout << fileName << endl;

}

return 0;

}





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top