Advertisement

Getting A List Of Files In A Directory

Started by May 22, 2001 06:53 PM
1 comment, last by Galileo430 23 years, 8 months ago
My 3D engine needs to be able to get a list of files in a given directory. I can''t figure out how it''s done without MFC? Does anyone here have any clue?
------------------------------------------------------------I wrote the best video game ever, then I woke up...
I had to do this for my game too, so if u need clarification, plz post again.

here is the general format:

  WIN32_FIND_DATA wfd;HANDLE          hFind;char szPath[]; // The directory to searchhFind = FindFirstFile( szPath, &wfd );do{ }while( FindNextFile(hFind, &wfd ) );FindClose(hFind);  


In the do loop, you can enumerate the files etc..., in my application I call the function again recursively for subdirectories.

wfd will contain information about the current element. i make use of the following properties in my code:


This i use to check if it is a subdirectory
  // If it is a directory and not "." or ".."if( ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) && wfd.cFileName[0] != ''.'' ){}  



This if it is just a normal file
  else if( wfd.cFileName && !( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) )  


Notice, u need to use the & to check for flags in the file attributes. wfd.cFileName is also useful. I would reccommend looking up the WIN32_FIND_DATA structure on MSDN, it has a lot of stuff, and is well documented. You can find out all the same stuff that the MFC FindFile thingy gives you.

Good luck, post again if you have further questions.
Advertisement
Thanks I needed that to.

This topic is closed to new replies.

Advertisement