how to find list of files in directory?

Started by
3 comments, last by dynamicman 21 years, 10 months ago
How would I find a list of files in a directory? I''m using VC++. Does win32 have any native functions to do this?
Advertisement
There might be newer functions than these, but check out _findfirst and _findnext



Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
Thank you very much!
FindFirstFile and FindNextFile are the ''official'' Win32 functions for doing that.

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;}  

This topic is closed to new replies.

Advertisement