Thread Einfache Datei-Operationen
(29 answers)
Opened by geloescht at 2012-09-26 22:17
Ganz kurz und einfach:
Code (perl): (dl
)
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 #!/usr/bin/perl use strict; use warnings; use File::Copy; use File::Spec; my $source_dir='.'; my $destination_dir='.'; my @files=( 'kunden.csv', 'kurzgeschichten.csv', 'kundencounter.csv', ); my $backup_name='%s-backup-%s'; my $date=make_date(); for my $source (@files) { my $source_path=File::Spec->join($source_dir,$source); my $destination=sprintf($backup_name,$date,$source); my $destination_path=File::Spec->join(destination_dir,$destination); if(-f $source_path) { unless(copy($source_path,$destination_path)) { warn("Can't copy $source_path => $destination_path ($!)\n"); } } else { warn("$source_path don't exists\n"); } } sub make_date { my ($day,$mon,$year)=(localtime())[3,4,5] $mon+=1; $year+=1900; return sprintf('%04u%02u%02u',$year,$mon,$day); } |