GetFileInfo Example

InstallShield 2016 » InstallScript Language Reference

Note • To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.

/*--------------------------------------------------------------*\

*

* InstallShield Example Script

*

* Demonstrates the GetFileInfo function.

*

* GetFileInfo is called to retrieve the time, date, and

* attributes of a file.

*

* Note: In order for this script to run correctly, you

*       must set the constant EXAMPLE_TXT to the name

*       of an existing file on the target system.

*

\*--------------------------------------------------------------*/

 

#define EXAMPLE_FILE "C:\\IO.sys"

#define TITLE_TEXT   "GetFileInfo Example"

 

// Include Ifx.h for built-in InstallScript function prototypes.

#include "Ifx.h"

 

export prototype ExFn_GetFileInfo(HWND);

 

function ExFn_GetFileInfo(hMSI)

    STRING svResult, szAttributes;

    NUMBER nvResult;

    LIST   listID;

begin

 

    // Create a list to store information about the file.

    listID = ListCreate (STRINGLIST);

 

    // Get the date the file was created or last updated into svResult.

    if (GetFileInfo (EXAMPLE_FILE, FILE_DATE, nvResult, svResult) = 0) then

        // Add the file date to the list.

        ListAddString (listID, "File date: " + svResult, AFTER);

    endif;

 

    // Get the time the file was created or last updated into svResult.

    if (GetFileInfo (EXAMPLE_FILE, FILE_TIME, nvResult, svResult) = 0) then

        // Add the file time to the list.

        ListAddString (listID, "File time: " + svResult, AFTER);

    endif;

 

    // Get the file attributes into nvResult.

    if (GetFileInfo (EXAMPLE_FILE, FILE_ATTRIBUTE, nvResult, svResult) = 0) then

      // Test for no attribute.

      if (nvResult = FILE_ATTR_NORMAL) then

          // No attributes are set.  Add that info to the list

          ListAddString(listID, "File attributes: Normal", AFTER);

      else

            // Append attributes to this string.

            szAttributes = "File attributes: ";

 

            // Is it archived?

            if (FILE_ATTR_ARCHIVED & nvResult) then

                szAttributes = szAttributes + "archived ";

            endif;

 

            // Is it hidden?

            if (FILE_ATTR_HIDDEN & nvResult) then

                szAttributes = szAttributes + "hidden ";

            endif;

 

            // Is it read-only?

            if (FILE_ATTR_READONLY & nvResult) then

                szAttributes = szAttributes + "read-only ";

            endif;

 

            // Is it a system file?

            if (FILE_ATTR_SYSTEM & nvResult) then

                szAttributes = szAttributes + "system ";

            endif;

 

            // Is it a directory?

            if (FILE_ATTR_DIRECTORY & nvResult) then

                szAttributes = szAttributes + "directory ";

            endif;

 

        endif;

 

        // Add the file attributes to the list.

        ListAddString (listID, szAttributes, AFTER);

 

    endif;

 

    // Display the list.

    SdShowInfoList (TITLE_TEXT, EXAMPLE_FILE, listID);

 

    // Remove the list from memory.

    ListDestroy (listID);

 

end;