• Advertisement

Archived

This topic is now archived and is closed to further replies.

listing files in a directory, HELP!

This topic is 5811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a function or way to list files in a specified directory? Or a suggested way to do this, plz help! I use Visual C++ 6.0. Thanks! .sen

Share this post


Link to post
Share on other sites
Advertisement
#include <windows.h>
#include <direct.h>
#include <stdio.h>
void ListDirectory(const char *path, const char *extension)
{
WIN32_FIND_DATA finddata;
HANDLE handle;
char searchPath[256];

_snprintf(searchPath,255, "%s%s", path, extension);

handle = FindFirstFile(searchPath, &finddata);

if (handle != INVALID_HANDLE_VALUE)
{
do
{
if(!(finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))// ignore directories, ., .., etc
{
printf("file : %s, size : %d bytes\n",finddata.cFileName,((finddata.nFileSizeHigh * MAXDWORD) + finddata.nFileSizeLow));
}

} while (FindNextFile(handle, &finddata));

FindClose(handle);
}
}

int main()
{
ListDirectory("c:\\","*.*");
return (0);
}

Share this post


Link to post
Share on other sites

  • Advertisement