Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.11 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # usage: ./date-correct.pl +1*60*60  *.jpg
  3. # 1. Argument: zu addierender Zeitoffset in Sekunden, etwa
  4. #   42 = 42 sekunden draufaddieren auf alle dateien-mtimes
  5. #  -12 = 12 Sekunden abziehen " " "
  6. #  -60*60 = 1h abziehen
  7. #  etc.
  8. #
  9. # Beispiele:
  10. #   ../Date-corrector.pl -60*60 001* 002* 003* 004*
  11. #        -> Bilder mit "001" bis "004" um 1h zurueck korrigieren
  12. #   find -newer 004.* -print0 | sort -z | xargs -0 -n1 ../Date-corrector.pl -60*60
  13. #        -> alle Bilder ab "004" nehmen, sortieren und einzeln um 1h zurueck korrigieren
  14.  
  15.  
  16. use strict;
  17. use File::stat;
  18. use POSIX  qw(strftime);
  19. sub touchf { return strftime "%y%m%d%H%M.%S", localtime($_[0]); }
  20.  
  21. my $ds = shift @ARGV;
  22. my $d = eval $ds; die "Delta-Zeitargument ($ds) falsch: $@" if $@;
  23. #print "Making $d seconds offset\n";
  24.  
  25. for(@ARGV) {
  26.     unless(-e) { die "File $_ does not exist!\n"; }
  27.     my $otime = stat($_)->mtime;
  28.     my $ntime = $otime + $d;
  29.     my $o = touchf($otime); my $n = touchf($ntime);
  30.     #print "$_: $otime => $ntime\n";
  31.     #print "$_: $o => $n\n";
  32.     my $cmd = "touch -t$n -m '$_'";
  33.     print "$d sec offset: $cmd\n";
  34.     `$cmd`;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement