home *** CD-ROM | disk | FTP | other *** search
- /*********
- * Utility: FATTRIB.C
- * by Leonard Zerman, Ralph Davis
- * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
- *
- * Syntax: FATTRIB <expC1> <expC2> ... <expCn>
- *
- * Note: Parameters are as follows, in any order:
- *
- * Filename, including extension
- *
- * Attributes, preceded by + to turn on or - to turn off
- * may be entered individually or together, i.e.:
- *
- * FATTRIB FILE.TXT -R -A +H
- * FATTRIB FILE.TXT -RA +H
- *
- * Attributes are:
- *
- * A--archive
- * H--hidden
- * R--read-only
- * S--system
- *********/
-
- #include "stdio.h"
- extern char * FIND_FIRST();
- extern char * FIND_NEXT();
-
- void main(argc,argv)
- int argc;
- char *argv[];
- {
- static char filename[65];
- static char attribs[] = " "; /* 11 spaces */
-
- int i = 0, j; /* indexes into attribute string and *argv[] */
- int file; /* file descriptor */
- int status; /* returns success or failure of operation */
- char *fnameptr;
-
- /* Check for valid number of arguments --get info if not entered */
-
- if (argc == 1)
- {
- fprintf(stderr,"\n\nPlease enter filename: ");
- gets(filename);
-
- fprintf(stderr,"\n\nPlease enter attributes (A/H/R/S): ");
- gets(&attribs[1]);
-
- fprintf(stderr,"\n\nPlease enter operation (+/-): ");
- attribs[0] = getchar();
-
- } else
-
- if (argc == 2)
- {
- if ((argv[1][0] == '+') || (argv[1][0] == '-'))
- {
- for (j = 0; argv[1][j]; j++)
- attribs[i++] = argv[1][j];
- fprintf(stderr,"\n\nPlease enter filename: ");
- gets(filename);
- }
- else
- {
- strncpy(filename, argv[1], 64);
- fprintf(stderr,"\n\nPlease enter attributes (A/H/R/S): ");
- gets(&attribs[1]);
-
- fprintf(stderr,"\n\nPlease enter operation (+/-): ");
- attribs[0] = getchar();
-
- }
- } else
-
- {
- while (--argc)
- {
- /* Is parameter the filename? Check first character
- for + or - */
-
- if ((argv[argc][0] == '+') || (argv[argc][0] == '-'))
- {
- for (j = 0; argv[argc][j]; j++)
- attribs[i++] = argv[argc][j];
- }
- else
- {
- strncpy(filename, argv[argc], 64);
- }
- }
- attribs[i] = '\0';
- }
-
- fnameptr = FIND_FIRST(filename);
- while(fnameptr)
- {
- file = open(fnameptr, 0);
-
- if (file == -1) /* File not found */
- {
- fprintf(stderr, "\007File %s not found\n", fnameptr);
- exit(1);
- }
- close(file);
- status = FILEATTR(fnameptr, attribs);
-
- if (status == 0)
- fprintf(stderr, "Attributes of file %s successfully changed\n\n",
- fnameptr);
- else
- fprintf(stderr, "\007Error changing attributes of file %s\n\n",
- fnameptr);
- fnameptr = FIND_NEXT();
- }
-
- }
-