xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

FileAttr()

Returns the attributes of a file.

Syntax

FileAttr( [<cFileName>] ) --> nAttributes

Arguments

<cFileName>
This is an optional character string containing the name of the file to query. It defaults to the last file found with FileSeek(). If specified, it must contain a file extension. If <cFileName> contains no drive and/or directory information, the current directory is used. SET DEFAULT and SET PATH settings are ignored.

Return

The function returns the attributes of a file as a numeric value, or -1 on error. See the example for decoding the return value.

Info

See also:FileDate(), FileSeek(), FileSize(), FileTime(), SetFAttr()
Category: CT:DiskUtil , File functions , Low level file functions
Source:ct\files.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example lists #define constants that can be used for
// decoding the return value of FileAttr()

   #define FA_NORMAL           0
   #define FA_RDONLY           1   /* R */
   #define FA_HIDDEN           2   /* H */
   #define FA_SYSTEM           4   /* S */
   #define FA_LABEL            8   /* V */
   #define FA_DIREC           16   /* D */
   #define FA_ARCH            32   /* A */
   #define FA_DEVICE          64   /* I */
   #define FA_TEMPORARY      256   /* T */
   #define FA_SPARSE         512   /* P */
   #define FA_REPARSE       1024   /* L */
   #define FA_COMPRESSED    2048   /* C */
   #define FA_OFFLINE       4096   /* O */
   #define FA_NOTINDEXED    8192   /* X */
   #define FA_ENCRYPTED    16384   /* E */
   #define FA_VOLCOMP      32768   /* M */


   PROCEDURE Main
      LOCAL aFiles := Directory( "\xhb\lib\*.*" )
      LOCAL aFile

      FOR EACH aFile IN aFiles
         ShowAttr( "\xhb\lib\" + aFile[1] )
      NEXT
   RETURN

   PROCEDURE ShowAttr( cFile )
      LOCAL nAttr := FileAttr( cFile )

      IF ( nAttr == -1 )
         ? "File not found ", cFile
         RETURN
      ENDIF

      ? "Attrib: "

      IF ( nAttr & FA_RDONLY ) > 0
         ?? "Readonly "
      ENDIF

      IF ( nAttr & FA_HIDDEN ) > 0
         ?? "Hidden "
      ENDIF

      IF ( nAttr & FA_SYSTEM ) > 0
         ?? "System "
      ENDIF

      IF ( nAttr & FA_DIREC ) > 0
         ?? "Directory "
      ENDIF

      IF ( nAttr & FA_ARCH ) > 0
         ?? "Archive "
      ENDIF

      IF ( nAttr & FA_NORMAL ) > 0
         ?? "Normal "
      ENDIF

      IF ( nAttr & FA_TEMPORARY ) > 0
         ?? "Temp "
      ENDIF

   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe