Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>dos_setfileattr</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
dos_setfileattr

Usage

   #include <dos.h>
   int dos_setfileattr(char *filepath, unsigned att):


Description

   Sets the current file attributes of the named file to those passed in the
   unsigned integer att. The char pointer filepath references a standard
   DOS path and filename as a null terminated string. Individual file
   attributes can be set by oring att with the appropriate masks. The
   following macros are defined in dos.h and can be used for that purpose:

       FA_NORMAL   no attributes set
       FA_RDONLY   read only
       FA_HIDDEN   hidden
       FA_SYSTEM   system
       FA_ARCH     archive

   dos_setfileattr is not available for directories or the volume label.

Example 

   #include <dos.h>

   #include <io.h>
   #include <stdio.h>
   #include <stdlib.h>

   int main()
   {
       int fd;
       unsigned attribute;

       printf("Creating temporary file\n");
       fd = dos_creat("temp.fil",FA_RDONLY);

       if (fd == -1)
           {
           perror("Error opening file");
           exit(EXIT_FAILURE);
           }
       dos_getfileattr("temp.fil",&attribute);

       if (attribute & FA_RDONLY)

           printf("temp.fil is read only\n");
       else
           printf("temp.fil is not read only\n");

       if (attribute & FA_ARCH)
           printf("temp.fil has its archive bit set \n");
       dos_setfileattr("temp.fil",FA_NORMAL);
       dos_getfileattr("temp.fil",&attribute);

       if (attribute & FA_RDONLY)
           printf("temp.fil is read only\n");
       else
           printf("temp.fil is not read only\n");

       if (attribute & FA_ARCH)
           printf("temp.fil has its archive bit set \n");

       if (unlink("temp.fil") == 0)
           printf("\nTemporary file deleted OK\n");
       else {

           perror("Error deleting file");
           return EXIT_FAILURE;
       }
       return EXIT_SUCCESS;
   }

Return Value

   0 if succesful otherwise the DOS error code

See Also

   DOS package, dos_getfileattr



See Also: dos_getfileattr

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