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

Last reviewed: June 27, 1995
Article ID: Q126454
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a

SUMMARY

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

  • The C code you need to create an FLL.
  • The FoxPro code you need to call the FLL.

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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 27, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.