//	ListFiles.cp#ifdef macintosh	#include <Files.h>#else	#include <sys/types.h>	#include <sys/dir.h>		// see "man directory" for details#endif#include "ListFiles.h"StringList ListFiles( const FilePath& path ){	StringList list;	// make sure the given path specifies a directory	if (path.FileType() != kDirectory) return list;	  #ifdef macintosh  	CInfoPBRec	cipbr;						// local parameter block	HFileInfo	*fpb = (HFileInfo *)&cipbr;	// two pointers	DirInfo	*dpb = (DirInfo *) &cipbr;	OSErr	err;	short	idx;	String	pathname = path.ToString(kNative);	String	temp = pathname;	// first, get volume reference number via PBHGetVInfo...	HVolumeParam	hpb;	hpb.ioNamePtr = temp;		// (use temp, since it will be overwritten)	hpb.ioVRefNum = 0;			// use pathname, not ref num	hpb.ioVolIndex = -1;		// don't use volume index either	err = PBHGetVInfo( (HParmBlkPtr)&hpb, FALSE );	if (err) return list;		// bail out if can't get volume info	short volID = hpb.ioVRefNum;	// next, get directory ID via PBGetCatInfo...	fpb->ioVRefNum = 0;			fpb->ioNamePtr = pathname;	// partial pathname, and buffer to receive name	fpb->ioDirID = 0;			// search from working directory	fpb->ioFDirIndex = 0;		// gimme info about the named directory	err = PBGetCatInfo( &cipbr, FALSE );	// *** get the catalog info ***	if (err) return list;			// if error getting directory info, then bail out	long dirID = dpb->ioDrDirID;	// get directory ID for subsequent searching		// now loop through files using PBGetCatInfo...	fpb->ioVRefNum = volID;	for( idx=1; TRUE; idx++) {		fpb->ioDirID = dirID;		// set ioDirID on each loop		fpb->ioFDirIndex = idx;		// index of entry to return		err = PBGetCatInfo( &cipbr, FALSE );		if (err) break;				// exit when no more entries		pathname.FixAsPString();	// clean up after received Pascal string		/*		if (fpb->ioFlAttrib & 16) {			cout << "DIR:  " << pathname << endl;		}		else {			cout << "FILE: " << pathname << endl;		}*/		list.append( pathname );	}	  #else	DIR *dirp;	direct *dp;	dirp = opendir((String)path);	if (dirp == NULL) return list;	while ((dp = readdir(dirp)) != NULL) {//		cout << "DIR OR FILE: " << dp->d_name << endl;		list.append( dp->d_name );	}	closedir(dirp);	  #endif	return list;}