Luego del salto...
#!/usr/bin/perl #=============================================================================== # # FILE: copyphoto.pl # # USAGE: ./copyphoto.pl # # DESCRIPTION: # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Nomar Oscar Mora (NM),# COMPANY: UNOSoft # VERSION: 1.0 # CREATED: 02/06/2008 07:16:18 PM VET # REVISION: --- #=============================================================================== use strict; use warnings; use Getopt::Long; use Pod::Usage; use File::stat; use File::Copy; use POSIX qw(strftime); #--------------------------------------------------------------------------- # Configurar Getopt #--------------------------------------------------------------------------- Getopt::Long::Configure ("bundling", "ignorecase_always"); #--------------------------------------------------------------------------- # Variables #--------------------------------------------------------------------------- my $fuente = ""; my $destino = ""; my $help = 0; #--------------------------------------------------------------------------- # Main #--------------------------------------------------------------------------- opciones(); proceso(); #--------------------------------------------------------------------------- # Subrutinas #--------------------------------------------------------------------------- sub opciones { pod2usage("$0: especifique los directorios.") and exit(0) if ((@ARGV == 0) && (-t STDIN)); GetOptions ('f|fuente=s' => \$fuente, 'd|destino=s' => \$destino, 'help|h' => \$help) or pod2usage(2) and exit(0); pod2usage(1) and exit(0) if $help; } sub proceso { opendir (FUENTE, $fuente) or die "no se pudo abrir el directorio $fuente $!"; while(defined(my $archivo = readdir(FUENTE))){ my $completo_fuente = $fuente . "/" .$archivo; my $st = stat($completo_fuente); my $fecha = strftime "%Y-%m-%d", localtime $st->mtime; my $completo_destino = $destino . "/" . $fecha; if (not (-d $completo_destino )) { print "No hay directorio $completo_destino\n"; print "Creando $completo_destino ...\n"; mkdir ($completo_destino, 0755); } print "Moviendo $archivo a $completo_destino ...\n"; move ($completo_fuente, $completo_destino) or warn ("No se pudo copiar: $!"); } } #--------------------------------------------------------------------------- # Fin del programa #--------------------------------------------------------------------------- __END__ =head1 NAME copyphoto.pl - Script de respaldo de fotos. =head1 SYNOPSIS copyphoto.pl [--help|h] [--fuente|-f] dir [--destino|d] dir =head1 OPTIONS =over 8 =item B<--fuente> directorio fuente de los archivos =item B<--destino> directorio donde copiaran los archivos =item B<--help> muestra esta ayuda =item B<-h> muestra esta ayuda =back =head1 DESCRIPTION B toma los archivos del directorio fuente y los copia en el destino ordenados en directorios con la fecha. =cut
No hay comentarios:
Publicar un comentario