home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
guit01.zip
/
DIRLIST.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-30
|
5KB
|
177 lines
/*********************************************************** C++ SOURCE *****
*
* (C) Copyright JBA International Plc - 1993
* Licensed Material - Program Property of JBA.
* Not to be used for other than licensed and/or agreed purposes.
*-------------------------------------------------------------------------
*
* Project: GUIDELINES
*
* Component: Custom Controls
*
* Module: DirList.CPP
*
* Original Author: Jon Wright
*
* Description: This file contains an object which reads in a list
* of the files from a directory. This list may
* then be accessed by a JOT program. It is a trivial
* program to demonstrate how to interface to external
* from within Guidelines
*
* Environment: OS/2 V2.1 - IBM CSet++
*
* Modification history:
*
* 24nov93 : Initial release jw
*
* $Log$
*
***************************************************************************/
/**************************************************************************
* Include Local files
*************************************************************************/
#include "dirlist.hpp"
/**************************************************************************
* DirList Methods
*************************************************************************/
/**************************************************************************
* Function: DirList
*
* Purpose: Constructor: Create empty object
*
* Parameters: none
*
* Returns: none
*
*************************************************************************/
DirList::DirList (void)
{
count = 0;
ptrList [0] = 0;
}
/**************************************************************************
* Function: DirList
*
* Purpose: Constructor: Create and initialise with files list
*
* Parameters: Filespec of files to log
*
* Returns: none
*
*************************************************************************/
DirList::DirList (char *DirName)
{
RefreshList(DirName);
}
/**************************************************************************
* Function: DirList
*
* Purpose: Destructor: Delete object and any list entries.
*
* Parameters: none
*
* Returns: none
*
*************************************************************************/
DirList::~DirList ()
{
int i=0;
while ((ptrList[i] != 0) && (i<LISTLEN))
{
delete ptrList[i++];
}
}
/**************************************************************************
* Function: RefreshList
*
* Purpose: Allocates strings containing file names and adds them to
* the list.
* (note - almost no error checking!)
*
* Parameters: Filespec on which to search
*
* Returns: -1 if error, 0 if OK.
*
*************************************************************************/
short DirList::RefreshList (char *DirName)
{
FILEFINDBUF3 findbuf;
HDIR hDir = HDIR_CREATE;
ULONG ulSearchCount = 1; // Read 1 entry at a time
count = 0;
memset(&findbuf,0,sizeof(FILEFINDBUF3) );
if (DosFindFirst( DirName,
&hDir,
FILE_NORMAL,
&findbuf,
sizeof(findbuf),
&ulSearchCount,
FIL_STANDARD))
{
DosBeep(700,110);
return -1;
}
while(ulSearchCount && (count < LISTLEN))
{
if (ptrList[count])
{
delete ptrList[count];
}
ptrList[count] = new String(findbuf.achName);
count++;
if (DosFindNext(hDir, &findbuf, sizeof(findbuf), &ulSearchCount))
{
break;
}
}
return 0;
}
/**************************************************************************
* Function: ReadItem
*
* Purpose: Retrieves item from list
*
* Parameters: Index - index of item in list to be retrieved
*
* Returns: Pointer to a Guidelines String, or null if invalid index.
*
*************************************************************************/
String *DirList::ReadItem (int Index)
{
if (Index < count)
{
return ptrList[Index];
}
else
{
return 0;
}
}