How do I read the contents of a folder?

Started by
2 comments, last by Cibressus 18 years, 12 months ago
I want to scan the savegame folder for any saved game files. I thought of making an index file into which names of savegames would be written upon saving and read when accesing the load menu. This would work as long as the user doesen't manualy delete any saves. But you know what are some end-users like. I'm guessing that folders are just files consisting of pointers to other files. But how do I read this type of file? Or am I missing some easy and obvious way to do it?
Advertisement
Look up FindFirstFile, FindNextFile, and FindClose on MSDN.
I'm not 100% that this is what you would like to implement, but I personally use the _findfirst() and _findnext() functions:

_findfirst() accepts a root path (can just be the drive), and a pointer to a _finddata_t structure which describes the first file found which satisfies the wildcard (if given), and a handle to this search (or -1 if none are found).

After calling _findfirst(), you then repeatedly call _findnext(), passing the handle which _findfirst() returns and another _finddata_t pointer, until _findnext() returns -1 (meaning no files remain to be returned).

I know this is not a particulary concise explanation, but look these functions up in the MSDN help files or ask if you would like to know more.

P.S. This is probably an outdated method for searching for files, but its worked well enough for me for years...

-Scoot
lucky you, i just got done reading the section on it.

in managed code you can DirectoryInfo and FileInfo classes in the system.io namespace.
| Member of UBAAG (Unban aftermath Association of Gamedev)

This topic is closed to new replies.

Advertisement