Skip to main content
GameDev.net gamedev.net
🔒 Locked

Directory Listings

Started by Reactivore Jun 30, 2000 at 2:08 PM 0 replies 250+ views
Original Post
Reactivore
Reactivore
This is probably a really dumb question, but I am developing a GUI for my application in DX, and I have come to the point where I need a file viewing window, so that I can get the location string of a user selected file and use it to open the file. However, since this is in my GUI, I am trying not to use any windows functions that would bring up an open dialogue box. I am just trying to get a function (or any way really) that will give me directory listings so that I can make my own dialogue box, like in nesticle (a nintendo emulator). I am using VC++ 6. Thanks guys. Looking forward to hearing what you have to say.
win32mfc
win32mfc
Well, I think you have to do all the text/input display yourself.
In that case, you just need to get a list of all the files in a particular directory, right?

Here is a routine I wrote that uses MFC''s CStringArray class to hold the filenames, but you can replace that easily. You probably want the ::FindFirstFile() and ::FindNextFile().

When calling this routine, the [szFileSpec] can be "*.*" or "*.sav" or whatever for special filtering. Check the MSDN reference for the function''s usage.

BTW, in the code below, I filter out directories that match - it only returns actual files.


// CHRIS

CODE FOLLOWS:


void GetMatchingFiles(LPCTSTR szFileSpec, CStringArray& rvList)
{
HANDLE hFind;
WIN32_FIND_DATA fd;

if ((hFind = ::FindFirstFile ((LPCTSTR) szFileSpec, &fd)) != INVALID_HANDLE_VALUE) {

if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
rvList.Add(fd.cFileName);
}

while (::FindNextFile (hFind, &fd)) {
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
rvList.Add(fd.cFileName);
}
::FindClose(hFind);
}
}
// CHRIS [win32mfc]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.