Obtain File Format Information

KeyView allows you to obtain the following basic information for a file:

You can obtain the file format information by using the fpGetFileInfo() function pointer.

You call fpGetFileInfo() with the path to the file, and a pointer to a KVDocInfo structure that KeyView can fill with the file details. For more details about the fpGetFileInfo() function pointer, see C API Reference.

Get the Types of Files in a List

The following example illustrates how to:

NOTE: If a call to fpGetFileInfo is unsuccessful, the KVDocInfo structure is not modified. The return value of fpGetFileInfo is therefore ignored in this example because the KVDocInfo structure is left zero-filled with the character set equal to KVCS_UNKNOWN, the document class to set to AutoDetNoFormat, and the file type of Unknown_Fmt.

#include "kvpdf.h"

void getTypesOfFilesInList(
    const KVPDFInterface sInterface,
    const char* const pszKeyViewDir,
    const char* const pszTempFolder,
    const char* const * const ppszFileNames,
    ENdocFmt* const peFileTypesOutput,
    const unsigned int numberOfFiles)
{
    KVPDFContext context = NULL;
    unsigned int i = 0;

    if(sInterface.fpInit(
            pszKeyViewDir, pszTempFolder, &context
        ).eErrorCode != KVERR_Success)
    {
        return;
    }

    for (i = 0; i < numberOfFiles; i++)
    {
        // (ENdocFmt) 0 = Unknown_Fmt
        KVDocInfo sDocInfo = {0};
        sInterface.fpGetFileInfo(context, ppszFileNames[i], &sDocInfo);
        peFileTypesOutput[i] = sDocInfo.adInfo.eFormat;
    }

    sInterface.fpShutDown(&context);
}