Introduction
CSADirRead
is a class that will generate a list of files and folders contained in a folder of your choice.
Usage
First, declare a CSADirRead
object
#include "SADirRead.h"
...
CSADirRead dr;
First, we build our list of folders to scan.
dr.ClearDirs();
dr.GetDirs("c:\\temp", true);
CSADirRead::SADirVector &dirs = dr.Dirs();
for (CSADirRead::SADirVector::iterator dit = dirs.begin();
dit!=dirs.end(); dit++)
{
TRACE("%s\n", (*dit).m_sName);
}
Now that the object knows which directories to scan, tell it to scan for files:
dr.ClearFiles();
dr.GetFiles("*.jpg");
CSADirRead::SAFileVector &files = dr.Files();
for (CSADirRead::SAFileVector::iterator fit = files.begin();
fit!=files.end(); fit++)
{
TRACE("%s\n", (*fit).m_sName);
}
Because you can access and modify the folder list before scanning for files, you can manually add folders to (or remove folders from) the folder list. Likewise, you can call GetDirs()
multiple times to build up the folder list before scanning for files, like this:
dr.ClearDirs();
dr.GetDirs("c:\\temp", true);
dr.GetDirs("c:\\windows", false);
dr.ClearFiles();
dr.GetFiles("*.JPG");
Sorting the results
After building the file list, you can sort the files using CSADirRead::SortFiles
. CSADirRead
has three built-in sorting methods - alphabetic, date and size - and can sort in ascending or descending order.
Get a list of subfolders in c:\windows
CSADirRead dr;
dr.GetDirs("c:\\windows", false);
dr.GetFiles("*.*", false, true);
CSADirRead::SAFileVector &files = dr.Files();
Now, files
will have a list of subfolder of C:\Windows (no files included, just the folders)
History
- 20 Jan 2002 - updated download
- 24 May 2002 - updated download
- 3 March 2003 - new revision.