• Advertisement

Archived

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

how to find list of files in directory?

This topic is 5712 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

How would I find a list of files in a directory? I''m using VC++. Does win32 have any native functions to do this?

Share this post


Link to post
Share on other sites
Advertisement
This is an example of how to use the functions:


  
HRESULT ScanFiles(char *szPath)
{
if( szPath == NULL )
return E_INVALIDARG;

WIN32_FIND_DATA wfd;
HANDLE hFind;

hFind = FindFirstFile( szPath, &wfd );
do
{
// If it is a directory and not "." or ".."

if( ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) &&
wfd.cFileName[0] != ''.'' )
{
// You could form a new path name by appending

// wfd.cFileName to your current path, and

// call this funciton recursively to explore all

// subdirectories in the hierarchy

}

else if( wfd.cFileName &&
!( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )
{
// This is a file

}
}
while( FindNextFile(hFind, &wfd ) );

FindClose(hFind);

return S_OK;
}

Share this post


Link to post
Share on other sites

  • Advertisement