Re: CListCtrl and file system
Here are some things you could consider:
1. You could detect the device change if your program is running and then
just scan through the folder tree using CFileFind and scan each of the
folders.
2. You could build an "object" for each folder/file that you find including
a pointer to the folder, the human readable name, and anything else you'd
need to display it.
3. You could store the objects in an object list.
4. Then you could scan the final list and add the descriptions to a drop
down combo or list box so the user could display the one they want.
5. When the user selects an item you already have a path to the file(s) for
that item in our coorelating object (in the list).
Here is a code snippet I wrote for creating folders in a tree. Perhaps it
will help you to traverse the tree as well. I would do this recursively (as
you come to a sub folder work your way down then eventually you will work
your way back out).
//
// Create all folders needed to get to a path if they are not already there.
//
void CreateAllDirectories(CString strDir)
{
if(strDir.IsEmpty())
return;
// remove ending / if exists
RemoveSlash(strDir);
// base case . . .if directory exists
if(FileExists(strDir))
return;
// recursive call, one fewer directories
int nFound = strDir.ReverseFind(_T('\\'));
CreateAllDirectories(strDir.Left(nFound));
// actual work
CreateDirectory(strDir,NULL);
}
Your loop would be using the results of the CFileFind and you'd "recurse"
when you find a folder rather than a file to work your way down.
Tom
"Steve Kelley" <skelley@proteaninstrument.com> wrote in message
news:QRGri.25777$7G1.7646@bignews4.bellsouth.net...
Hello all,
I have an application where I need to give the user an interface to
select a folder from which my application will fetch some configuration
data. The idea is that there may be several folders on a USB key with
each folder containing configuration data for an instrument. The folder
name is a unique identifier that is not necessarily a human friendly
name. What I want to do is load a selection list with human friendly
names that come from the configuration files. So, the user needs to be
able to browse to a folder that contains the sub folders that contain
the configuration files. My program needs to be able to scan for sub
folders containing the config files and read the instrument's name and
place it in a list box for selection. It would be like using the file
open dialog where the file list would be empty until the config data's
parent directory is selected then the folders containing the config data
would appear as files in the selection box. I know how to get the
instrument names once I am in the parent directory but since I have
never had to deal much with the file system I'm not at all sure how to
navigate the tree or where to start. Any pointers or references would be
appreciated.
--
Steve Kelley