Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ChangeFileTime(char const * const name, char const * const timeStr)
- {
- time_t atime=0,mtime=0;
- struct stat attr;
- if(stat(name,&attr)==-1)
- {
- perror("error in stat, ChangeFileTime");
- return;
- }
- atime=attr.st_atim.tv_sec; //lade Zeit für letzten lesenden Zugriff
- mtime=attr.st_mtim.tv_sec;
- struct utimbuf ttime;
- long d=0,h=0, m=0,s=0;
- char *str=timeStr;
- long x;
- errno = 0;
- while ( x = strtol(str, &str, 10), x!=0 && errno == 0) //string parsen
- {
- switch(*str)
- {
- case 'd': d+=x; *str++;break;
- case 'h': h+=x;*str++; break;
- case 'm': m+=x;*str++; break;
- case 's': s+=x;*str++;break;
- default: perror("Unspezifiertes Zeitformat!"); return; break;
- }
- }
- //Werte in Sekunden umwandeln
- d=d*24*60*60;
- m=m*60;
- h=h*60*60;
- s=s+d+h+m;
- atime+=s;
- mtime+=s;
- ttime.actime=atime;
- ttime.modtime=mtime;
- if(utime(name, &ttime)==-1) {
- perror("Fehler bei utime()\n");
- return;
- }
- printf("══════════════════════════════════════════════════════════════════════\n");
- printf("\n%s\n",name);
- printf("Aenderungsdifferenz in Sekunden : %i sec\n", s);
- printf("\n fuer die Datei %s\n", name);
- printf("══════════════════════════════════════════════════════════════════════\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment