Advertisement

File listings in C++? Help!

Started by January 22, 2001 11:45 PM
7 comments, last by Todd M Gillissie 24 years ago
I''ve been successful in using C++ to write and read my own binary files, but what I can''t figure out is how to do a simple directory listing so I can read all of the files in a directory, no matter how many there are. In MSDN, they have an MFC class called CFileFind, which would seem to do exactly what I want, but I don''t know anything about MFC, and the compile always gives me an error about missing externals when I compile. I''ve included afx.h like the instructions say, however my game program isn''t set up as an MFC project because I don''t want it to be. Is there a way to do this without MFC classes, or an easy way to get the CFileFind class to work in my non-MFC program. Maybe a way to minimally MFC-activate my program for this class to work? This seems much more difficult than it should. Thanks for any help. Todd M. Gillissie gillissie@yahoo.com
Todd M. Gillissiegillissie@yahoo.com
Check out theses functions:

opendir();
readdir();
closedir();
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Advertisement
I don''t see any reference to those function in MSDN, and Intellisense doesn''t pop anything up for them either.

Todd M. Gillissie
gillissie@yahoo.com
Todd M. Gillissiegillissie@yahoo.com
since your probably using windows try FindFirstFile functions:

WIN32_FILE_DATA w32fd;HANDLE fh = FindFirstFile( "c:\\*.*", &w32fd );if ( fh != INVALID_HANDLE_VALUE ){    do    {        //use w32fd.cFileName    } while ( FindNextFile( fh, &w32fd ) );    FindClose( fh );} 


hope that helps!

crazy166
some people think i''m crazy, some people know i am
readdir et al is POSIX so it should be there, but somehow Microsoft decided not to include them it seems. I keep asking myself; why? man gives a nice documentation of the very same functions, though


"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album
Crazy166,

Thanks for the nice code sample. The problem still remains. The classes you demonstrated are part of MFC, which I don''t have in my win32 project, and I don''t know how to get access to MFC without messing up the whole thing.



Todd M. Gillissie
gillissie@yahoo.com
Todd M. Gillissiegillissie@yahoo.com
Advertisement
Todd : FindFirstFile is not MFC. It''s a Win32 function and you should be able to call it from _any_ program (no matter if they are MFC, Win32 or console). The WIN32_FILE_DATA is a struct and, just like FindFirstFile, it belongs to the Win32 API.

Therefore, you shouldn''t have any problem in using them.
ok. After messing around some more and looking up the WIN32_FILE_DATA struct in MSDN, I realized that it is actually called WIN32_FIND_DATA.

Once I got that name correct, and figured out which headers I needed to include, it worked! Thanks a lot guys.



Todd M. Gillissie
gillissie@yahoo.com
Todd M. Gillissiegillissie@yahoo.com
oops, sorry about the typo!

crazy166
some people think i''m crazy, some people know i am

This topic is closed to new replies.

Advertisement