3 #=======================================================================
5 # File ID: ab0489f6-f744-11dd-ba4c-000475e441b9
7 # Syntax: mvdirnewest directory
8 # Forandrer navnet på directoryen til den nyeste fila i trestrukturen under.
9 # Brukes til å lage orden i gamle versjoner av ting som ligger slengende rundt.
11 # Character set: UTF-8
12 # ©opyleft 1999– Øyvind A. Holm <sunny@sunbase.org>
13 # License: GNU General Public License version 2 or later, see end of
14 # file for legal stuff.
15 #=======================================================================
35 $progname =~ s/^.*\/(.*?)$/$1/;
36 our $VERSION = "0.00";
38 Getopt
::Long
::Configure
("bundling");
41 "debug" => \
$Opt{'debug'},
42 "help|h" => \
$Opt{'help'},
43 "verbose|v+" => \
$Opt{'verbose'},
44 "version" => \
$Opt{'version'},
46 ) || die("$progname: Option error. Use -h for help.\n");
48 $Opt{'debug'} && ($Debug = 1);
49 $Opt{'help'} && usage
(0);
50 if ($Opt{'version'}) {
58 die("$progname: Unknown version of find(1) or program not found\n") unless (`find --version` =~ /GNU find/);
61 $RetVal ||= process_dir
($_);
68 unless (-e
$dir_name) {
69 warn("$progname: $dir_name: Directory not found\n");
72 unless (-d
$dir_name) {
73 warn("$progname: $dir_name: Not a directory\n");
79 # FIXME: Dette med find er midlertidig (og kommer sikkert til å forbli her :)
80 my @Files = `find "$dir_name" -type f`;
81 unless (scalar @Files) {
82 warn("$progname: $dir_name: No files found in directory\n");
89 unless (@stat_array = stat($file_name)) {
90 warn("$progname: $file_name: Can’t stat file: $!\n");
93 my $file_date = $stat_array[9];
94 if ($file_date > $newest_date) {
95 $newest_date = $file_date;
96 $newest_file = $file_name;
98 # printf("$file_name: %s\n", date2str($file_date));
100 my $new_name = sprintf("%s.%s", date2str
($newest_date), $dir_name);
102 warn("$progname: $new_name: Directory entry already exists, skipping directory $dir_name");
105 # printf("Skulle til å rename(%s, %s)\n", $dir_name, $new_name);
106 rename($dir_name, $new_name) || warn("$dir_name: Can’t rename directory to $new_name: $!");
107 print("$progname: $dir_name → $new_name\n");
113 my @TA = gmtime(shift);
114 return(sprintf("%04u%02u%02uT%02u%02u%02uZ", $TA[5]+1900, $TA[4]+1, $TA[3], $TA[2], $TA[1], $TA[0]));
118 # Print program version {{{
119 print("$progname v$VERSION\n");
124 # Send the help message to stdout {{{
127 if ($Opt{'verbose'}) {
133 Usage: $progname directory [directory [...]]
135 The program scans the underlying tree structure and renames the directory
136 to the date of the newest file.
143 Increase level of verbosity. Can be repeated.
145 Print version information.
147 Print debugging messages.
155 # Print a status message to stderr based on verbosity level {{{
156 my ($verbose_level, $Txt) = @_;
158 if ($Opt{'verbose'} >= $verbose_level) {
159 print(STDERR
"$progname: $Txt\n");
165 # Print a debugging message {{{
167 my @call_info = caller;
168 chomp(my $Txt = shift);
169 my $File = $call_info[1];
171 $File =~ s
#^.*/(.*?)$#$1#;
172 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
179 # Plain Old Documentation (POD) {{{
189 mvdirnewest directory [directory [...]]
193 The program scans the underlying tree structure and renames the directory
194 to the date of the newest file.
200 =item B<-h>, B<--help>
202 Print a brief help summary.
204 =item B<-v>, B<--verbose>
206 Increase level of verbosity. Can be repeated.
210 Print version information.
214 Print debugging messages.
220 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
224 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
225 This is free software; see the file F<COPYING> for legalese stuff.
229 This program is free software: you can redistribute it and/or modify it
230 under the terms of the GNU General Public License as published by the
231 Free Software Foundation, either version 2 of the License, or (at your
232 option) any later version.
234 This program is distributed in the hope that it will be useful, but
235 WITHOUT ANY WARRANTY; without even the implied warranty of
236 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
237 See the GNU General Public License for more details.
239 You should have received a copy of the GNU General Public License along
241 If not, see L<http://www.gnu.org/licenses/>.
249 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :