changing file times

Pierre Girard pierreg at siegfried.vlsi.polymtl.ca
Thu Nov 22 02:09:30 AEST 1990


Here is a small C program that can help you do this.

---- CUT HERE ---
/*
   This program can change the date and time of a file using the current 
   time a a reference.

   
   Arguments : [-d days] [-h hour] [-m minutes] -[s seconds]
               [file1][file2]...

   Defaults values give the same results as touch
   Programmer : Pierre Girard
   November 1990
*/
#include <utime.h>
#include <sys/time.h>

#define DAY  (24*HOUR)
#define HOUR (60*MIN)
#define MIN  (60*SEC)
#define SEC  (1)

main(argc,argv)
     int argc;
     char **argv;
{
  struct utimbuf times;

  time_t tloc;
  int i;

  int deltad=0,
      deltah=0,
      deltam=0,
      deltas=0;
  
  for(i=1;i<argc;i++)
    {
      if(!strcmp("-d",argv[i]))
	 {
	   ++i;
	   deltad=atoi(argv[i]);
	 }
      if(!strcmp("-h",argv[i]))
	 {
	   ++i;
	   deltah=atoi(argv[i]);
	 }
      if(!strcmp("-m",argv[i]))
	 {
	   ++i;
	   deltam=atoi(argv[i]);
	 }
      if(!strcmp("-s",argv[i]))
	 {
	   ++i;
	   deltas=atoi(argv[i]);
	 }
    }
      

  times.actime=  time(&tloc);     /* acces time */
  times.modtime= time(&tloc) + deltad* DAY+deltah*HOUR+deltam*MIN+deltas;     /* acces time */

  for (i=1;i<argc;i++)
    utime(argv[i],&times);

}

  
--

  ___   ___  ___  ___  ___  ___  ___
 /    /__   /__/ /__/ /__  /__/ /__
/__  /__   / \  /__/ /___ / \  /___

Pierre Girard, Student in computer ingeneering,
Ecole Polytechnique de Montreal, Quebec, Canada.
pierreg at info.polymtl.ca



More information about the Comp.unix.questions mailing list