-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathafv_rename
executable file
·78 lines (64 loc) · 2.14 KB
/
afv_rename
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env perl
#===============================================================
# afv_rename
# File ID: f7f4047c-5d36-11df-a766-90e6ba3022ac
# Leser filnavn fra stdin og skifter navn på dem fra gammelt
# afv-format (epoch) til ååååmmddTttmmssZ . Virker forsåvidt på
# alle filer som begynner med et 9- eller 10-sifret nummer.
#
# Character set: UTF-8
# License: GNU General Public License version 2 or later
# ©opyleft 2004 Øyvind A. Holm <[email protected]>
#===============================================================
use strict;
use warnings;
use Getopt::Std;
our ($opt_v) =
( 0);
getopts('v');
$| = 1;
while (<>) {
chomp();
if (/^(.*)\/([^\/]+?)$/) {
my ($Path, $File) =
( $1, $2);
if ($File =~ /^(.*?)\b(\d{9,10})\b(.*)$/) {
my ($First, $Num, $Rest) =
( $1, $2, $3);
my $From = "$Path/$File";
if (-f $From) {
my @TA = gmtime($Num);
my $date_str = sprintf("%04u%02u%02uT%02u%02u%02uZ", $TA[5]+1900, $TA[4]+1, $TA[3], $TA[2], $TA[1], $TA[0]);
my $Dest = "$Path/$First$date_str$Rest";
unless (-e $Dest) {
if (rename($From, $Dest)) {
$opt_v && print("$From → $Dest\n");
} else {
warn("rename(\"$From\", \"$Dest\"): $!\n");
}
} else {
warn("$Dest: File exists.\n");
}
} else {
warn("Ignoring non-regular file $From\n");
}
}
}
}
__END__
=pod
=head1 LICENCE
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
=cut
# vim: set fileencoding=UTF-8 filetype=perl foldmethod=marker foldlevel=0 :
# End of file afv_rename