0: #!/usr/bin/perl -w
1:
2: =pod
3:
4: =head1 savetime / loadtime
5:
6: This pair of simple scripts that are useful for making sure that
7: file times remain correct even after small updates.
8:
9: I use it to make sure that the photos from my digital camera have
10: the original times, even after some retouching or evil FTP clients
11: which do not set the right times...
12:
13: To install: Copy the file to somewhere within the path and make a
14: (symbolic) link to it, so that it appears in two names: loadtime and
15: savetime.
16:
17: =head2 savetime
18:
19: Creates the file '.filetimes' in the current directory and stores
20: access and modification time for all of the files in the current
21: directory.
22:
23: =head2 loadtime
24:
25: Resets the file times for all the files that have different time
26: than what is written in '.filetimes'.
27:
28: It will print one line for each file that is updated, containing the
29: number of seconds that have been changed.
30:
31: =cut
32:
33: if($0=~/savetime/)
34: { my @f=<*>;
35:
36: open(F, ">.filetimes") or die "open .filetimes: $!\n";
37: for (@f) {
38: my ($atime, $mtime)=(stat($_))[8,9];
39: print F "$_ $atime $mtime\n";
40: }
41: }
42:
43: if($0=~/loadtime/) {
44: die unless -f ".filetimes";
45:
46: open(F, "<.filetimes") or die "open .filetimes: $!\n";
47: while(<F>) {
48: my ($n,$a,$m) = split;
49: $atime{$n} = $a;
50: $mtime{$n} = $m;
51: }
52: close(F);
53:
54: for (<*>) {
55: my ($a, $m)=(stat($_))[8,9];
56: next if($a==$atime{$_} and $m==$mtime{$_});
57: print "$_ \t", $a-$atime{$_}, " \t",$m-$mtime{$_}, "\n";
58: utime $atime{$_}, $mtime{$_}, $_ or die "utime: $!\n";
59: }
60: }
In reply to savetime / loadtime by fundflow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |