TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Phil Crown
from: Morten Toftgaard Jensen
date: 1995-12-15 14:39:28
subject: PFILEFINDBUF3

Hey Phil!
 > {at}MSGID: 1:124/1208.0 30ce3321
 > Can anyone tell me why this does not work?  It will print the 
 > first file found, but nothing else.  The problems seem to be in 
 > getting a pointer to the next oNextEntryOffset;

The problem as I see it, is that you only allocate the FILEFINDBUF3
structure once, when fetching more than one file at a time. You have to
give a valid pointer to each call of DosFindFirst/DosFindNext of the size
required, which means that if you wish to fetch fileinfo for a hundred
files at a time, you need to allocate a buffer of "sizeof (FILEFINDBUF
* FILES_TO_GET)". The system does not allocate this buffer for you!

Try fetching one file at a time instead, with following code:

// ************************************************************ OPERATION
readDirectory
// This function does the actual reading of a directory, with
// the specified attributes and filter.
//
// The attribute mask is the mask containing the files you wish to get
// (FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED | FILE_SYSTEM |
//  FILE_DIRECTORY)
// The pathName, is the actual path, f.ex. "D:\OS2".
// The name mask is the files, by name, you wish to fetch, f.ex "*" for
// all files or "*.bat" for all the batch files.
//
// Output:  0 if success
//          DOS return code if error.



ULONG readDirectory (char* pathName, char* nameMask, ULONG attributeMask)
{
    FILEFINDBUF3    *fileFindBuffer;
    char            *pathNameMask;  // Used for full path + "\" +
wildcard mask
    APIRET          rc;             // Return code, for OS/2 functions
    HDIR            dirHandle=HDIR_SYSTEM;  // What kind of file handle we
allocate from system for directory
    AFileItem       *newFileItem;
    ULONG           searchCount=1;  // How many files to get info from, at a time

    pathNameMask=new char[constSVMaxPathLength];    // Allocate space for
DirList path name, including mask
                                                    // This entry is used
for DosFindFirst
    strcpy (pathNameMask, pathName); // Insert path

    if (pathNameMask[strlen(pathNameMask)-1] != '\\') strcat (pathNameMask,
"\\");      // Insert backslash

    strcat (pathNameMask, nameMask); // Insert file name mask

    fileFindBuffer = new FILEFINDBUF3;  // Allocate space for file information

    rc=DosFindFirst (pathNameMask,   // Path and name (including wildcards)
for file items allowed
                     &dirHandle,  // What kind of handle, does the
system assign/create for our application
                     attributeMask,   // What attributes are allowed or
should be set in file items
                     fileFindBuffer, // Pointer to buffer to insert information into
                     sizeof (FILEFINDBUF3),   // Size of the buffer to
insert information into
                     &searchCount,  // Request only one file item at a time
                     FIL_STANDARD ); // Request normal file information

    while (rc==0) { // Continue while there are file items in the directory

     // Those two lines allocates and inserts a file object of my type.
     // You can remove them and eventually write the name with a
     // simple printf ("name: %s\n", fileFindBuffer->achName),
or whatever.
        newFileItem=new AFileItem (fileFindBuffer); // Allocate and
initialize new file item
        insertFileItem (newFileItem);   // Insert file item into file list


        rc=DosFindNext (dirHandle, // Directory handle returned by DosFindFirst
                        fileFindBuffer,    // Pointer to file information
level 1 buffer
                        sizeof (FILEFINDBUF3), // Size of file information buffer
                        &searchCount);    // Fetch one file item
information buffer at a time

    } // End WHILE

    if (rc==0 || rc==18)	// If OK or no more files, return with success.
        return 0;
    else
        return rc;		// Otherwise return with error


}
// ************************************************************ End
OPERATION readDirectory

Hope this sorts you out.


Yours,

Morten T. Jensen
* Where do you want to go today? * Not the Microsoft way! *
* OS/2Net: 81:445/12.77 * FidoNet: 2:236/100.77 *
---
* Origin: Finally the patients have taken over the asylum! (2:236/100.77)
SEEN-BY: 270/101 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 517 628 713/888 800/1 7877/2809
@PATH: 236/100 235/47 236/9 235/50 240/5500 24/24 396/1 270/101 712/515
@PATH: 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.