Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - chmod() test or set file attributes http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 chmod()             Test or set file attributes
------------------------------------------------------------------------------
 Declaration
   file.hdr

 Syntax
   func int chmod extern
   param const char    cFileName, ;
         value uint    uAttribute, ;
         value logical lSet

 Arguments
   cFileName is the name of the file to manipulate.
   uAttribute contains the new file attributes.
   lSet indicates if the file attributes are to be set.

 Return
   The current file attributes, or -1 if the file does not exist.

 Description
   chmod() tests or sets file attributes. If lSet is .f., the function
   returns the current attributes of the specified file. If this parameter is
   .t., the attributes are set to the specification in uAttribute.

   The constants:

   #define CHMOD_GET .f.
   #define CHMOD_SET .t.

   are defined in file.hdr.

   The function returns -1 if there was an error detected (e. g. file
   not found, or illegal attribute specification in uAttribute).

   See the File attribute table for valid file attributes. Any combination,
   i. e. sum, of the attributes is allowed.

 Example
   #define EXAMPLE_FILE
   #include example.hdr

   proc ArchiveAll
   // Reset the archive bit on all files in the current path
   vardef
      uint uAttr
   enddef
   if findfirst( "*.*", FIND_ANYFILE )
      repeat
         uAttr := chmod( findfstr(), 0, CHMOD_GET )
         resetbit( uAttr, 0x05 )
         chmod( findfstr(), uAttr, CHMOD_SET )
      until .not. findnext()
   endif
   endproc
   
   proc Test_chmod
   vardef
      char cFile
   enddef
   cFile := curdir( 0 ) + "\"
   createtempfile( cFile )         // create a temporary file
   ? chmod( cFile, 0, CHMOD_GET )  // print current attributes
   chmod( cFile, 0x01, CHMOD_SET ) // set readonly attribute
   ? chmod( cFile, 0, CHMOD_GET )  // print changed attributes
   ArchiveAll()
   endproc

   proc main
   Test_chmod()
   endproc

See Also: fileattrib() findfattr() getfiletime() setfiletime()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson