How to Set File Attributes: Use C to Create FLL & Then Call It

ID: Q126454

The information in this article applies to:

SUMMARY

You can change the attributes of a file in FoxPro for Windows without performing a RUN ATTRIB <attributes> <filename>. This article contains:

MORE INFORMATION

C Code to Create an FLL that Can Be Called from FoxPro

#include <dos.h>
#include <pro_ext.h>

void FAR SetFA(ParamBlk FAR *parm)
{
#define FN (parm->p[0].val)
#define FA (parm->p[1].val)

char FAR *FName;
unsigned FAttr, retst;

if(!_SetHandSize(parm->p[0].val.ev_handle, parm->p[0].val.ev_length + 1))

//
 null terminate string
{
   _Error(182);
} _HLock(FN.ev_handle); _HLock(FA.ev_handle);

FName = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle); FName[parm->p[0].val.ev_length] = '\0';

FAttr = (unsigned) FA.ev_long; // set FAttr value and convert second

                                // attribute from integer to unsigned.

retst=_dos_setfileattr(FName, FAttr);   // change file attribute

_HUnLock(FN.ev_handle); _HUnLock(FA.ev_handle);

_RetInt(retst, 10); // return success or failure (0 = success) otherwise DOS

 error
}

FoxInfo myFoxInfo[] = {

     {"ATTRIB", (FPFI) SetFA, 2, "C, I"},
};

FoxTable _FoxTable = {

     (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

FoxPro Code Sample Showing How to Use the FLL

The following FoxPro code shows by example how to use the FLL to change the attributes of the file CUSTOMER.DBF to read only, and then reset all of the attributes. Also included is a table showing what each of the numbers means to the function _dos_setfileattr.

  * Table of properties for _dos_setfileattr:
  * 0 - unset all attributes
  * 1 - read only
  * 2 - hidden
  * 3 - read only/hidden
  * 4 - system
  * 5 - read only/system
  * 6 - hidden/system
  * 7 - read only/hidden/system

  SET LIBRARY TO SYS(2004)+"fileattr.fll"
  FileStat=ATTRIB("C:\FOXPROW\TUTORIAL\CUSTOMER.DBF",1)
  IF FileStat=0
    WAIT WINDOW "Attribute of CUSTOMER.DBF set to read only"
  ELSE
    WAIT WINDOW "DOS Error: "+STR(FileStat)+" setting file attribute"
  ENDIF
  FileStat=ATTRIB("C:\FOXPROW\TUTORIAL\CUSTOMER.DBF",0)
  IF FileStat=0
    WAIT WINDOW "Attribute of CUSTOMER.DBF reset"
  ELSE
    WAIT WINDOW "DOS Error: "+STR(FileStat)+" setting file attribute"
  ENDIF
  SET LIBRARY TO

Additional reference words: FoxWin 2.50 2.50a 2.50b 2.60 2.60a KBCategory: kbtool kbcode kbprg KBSubcategory: FxtoolLck

Last Reviewed: June 27, 1995