An application can retrieve and set information about a specific file by using DosQueryFSInfo and DosSetFileInfo. File information consists of the dates and times that the file was created, last accessed, and last written to (only the time and date the file was last written to are given for FAT partitions); the size (in bytes) of the file; the number of sectors (or clusters) the file occupies; and the file attributes.

The following code fragment obtains file information for a specified file. The example obtains the Level 1 information set for the file. The Level 1 information set for a file includes the dates and times of creation, last access, and last writing. It also includes information about the size of the file and the file's standard attributes. Assume that the handle of the desired file has been placed into FileHandle already.

    #define INCL_DOSFILEMGR   /* File System values */
    #include <os2.h>
    #include <stdio.h>

    HFILE        hfFileHandle;      /* File handle                 */
    ULONG        ulFileInfoLevel;   /* Level of file info required */
    FILESTATUS3  fsFileInfoBuf;     /* File info buffer            */
    ULONG        ulFileInfoBufSize; /* File data buffer size       */
    APIRET       ulrc;              /* Return code                 */

    ulFileInfoLevel = 1;  /* Indicate that Level 1 information is desired */

    fsFileInfoBufSize = sizeof(FILESTATUS3);
                          /* Size of the buffer that will                 */
                          /* receive the Level 1 information              */

    ulrc = DosQueryFileInfo(hfFileHandle,
                            ulFileInfoLevel,
                            &fsFileInfoBuf,
                            ulFileInfoBufSize);

    if (ulrc != 0) {
        printf("DosQueryFileInfo error: return code = %ld", ulrc);
        return;
    }

In this example, Level 1 file information is placed into the FileInfoBuf buffer.


[Back] [Next]