how to find list of files in directory?
How would I find a list of files in a directory? I''m using VC++. Does win32 have any native functions to do this?
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
Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
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
Popular Topics
Advertisement