home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / pcw_c.zip / TOUCH.C < prev    next >
Text File  |  1990-01-16  |  4KB  |  106 lines

  1. /**********************************************************/
  2. /* Program Id.               Touch.C                      */
  3. /* Author.                   Stan Milam.                  */
  4. /* Date Written.             31 Aug. 89.                  */
  5. /* Compiler.                 Mix Power C V1.3             */
  6. /*                                                        */
  7. /*          (c) Copyright 1989-90 by Stan Milam           */
  8. /*                                                        */
  9. /* Comments: This program is used to change file date and */
  10. /* times.  This has applications for make utilities.      */
  11. /**********************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #ifdef __TURBOC__
  17. #   include <io.h>
  18. #   include <dir.h>
  19. #   define  FA_NORMAL 0
  20. #else
  21. #   include <direct.h>
  22. #endif
  23. #include <dos.h>
  24.  
  25. /**********************************************************/
  26. /*                      get_date_time()                   */
  27. /*                                                        */
  28. /* Get the system date & time from DOS and store in the   */
  29. /* ftime structure.                                       */
  30. /**********************************************************/
  31.  
  32. void get_date_time(struct ftime *f_time) {
  33.  
  34.      struct time d_time;               /* Structure for DOS time */
  35.      struct date d_date;               /* Struct for Dos Date */
  36.  
  37.      getdate(&d_date);                 /* Get System Date */
  38.      gettime(&d_time);                 /* Get System Time */
  39.      f_time->ft_year = d_date.da_year - 1980;
  40.      f_time->ft_month= d_date.da_mon;
  41.      f_time->ft_day  = d_date.da_day;
  42.      f_time->ft_hour = d_time.ti_hour;
  43.      f_time->ft_min  = d_time.ti_min;
  44.      f_time->ft_tsec = d_time.ti_sec / 2;
  45. }
  46.  
  47. /**********************************************************/
  48. /*                           Main                         */
  49. /*                                                        */
  50. /* 1. Initialize ftime structure.                         */
  51. /* 2. Identify path specification                         */
  52. /* 3. Get first file spec.                                */
  53. /* 4. Repeat                                              */
  54. /*      A. Build file name.                               */
  55. /*      B. Open file and handle any errors.               */
  56. /*      C. Set file time & date equal ftime structure     */
  57. /*      D. Close file.                                    */
  58. /*    Until no more matching files.                       */
  59. /* 5. Clean up.                                           */
  60. /**********************************************************/
  61.  
  62. int main(int argc, char *argv[]) {
  63.  
  64.     struct ftime f_time;
  65.     struct ffblk fstruct;
  66.     static char  wrkstr[80], *wrk;
  67.     int    filecount = 0, lcv;
  68.     FILE   *fp;
  69.  
  70.     puts("\nTOUCH version 1.00 by Stan Milam");
  71.     if (argc < 2) {
  72.        puts("Error:  No filespec\nFormat: TOUCH filespec filespec....");
  73.        return(3);
  74.     }
  75.     get_date_time(&f_time);
  76.  
  77. /* Make TOUCH work with non-default drive and directories (with paths) */
  78.  
  79.     for (lcv = 1; lcv < argc; lcv++) {
  80.         strcpy(wrkstr, argv[lcv]);
  81.         if ((wrk = strrchr(wrkstr, '\\')) != NULL) wrk++;
  82.         else {
  83.            if ((wrk = strrchr(wrkstr,':')) != NULL) wrk++;
  84.            else wrk = wrkstr;
  85.         }
  86.         if (findfirst(argv[lcv], &fstruct, FA_NORMAL) == 0) {
  87.            printf("Touching %s\n",argv[lcv]);
  88.            do {
  89.               strcpy(wrk,fstruct.ff_name);
  90.               fp = fopen(wrkstr, "r+b");
  91.               if (fp == NULL) {
  92.                  printf("Error touching file: (%s)\n",wrkstr);
  93.               }
  94.               else {
  95.                  setftime(fileno(fp), &f_time);
  96.                  fclose(fp);
  97.                  filecount++;
  98.              }
  99.            } while (findnext(&fstruct) == 0);
  100.        }
  101.        else printf("(%s) *** No matching files ***\n", argv[lcv]);
  102.     }
  103.     printf("%d File(s) TOUCHED\n", filecount);
  104.     return(0);
  105. }
  106.