Leser: 22
1 2 3 4 5 6 7
use strict; use warnings; use File::Copy::Recursive qw(dircopy); my $fromdir = '/tmp/myfiles'; my $todir = '/home/peter'; dircopy($fromdir,$todir) or die $!;
my $returnval = qx( cp -a $fromdir/* $todir/ );
my $returnval = qx( xcopy /S /E /V $fromdir\*.* $todir\ );
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
#!/usr/bin/env perl use warnings; use strict; use File::Find; use File::Copy; use File::Basename; use File::Spec::Functions; die "usage: $0 'source_directory' 'target_directory'\n" unless @ARGV == 2; my $source_dir = $ARGV[0]; my $target_dir = $ARGV[1]; die "$source_dir is not a directory\n" if ! -d $source_dir; die "$target_dir is not a directory\n" if ! -d $target_dir; die "$target_dir: absoluter Pfad notwendig" if $target_dir !~ m|^/|; $target_dir = catdir( $target_dir, basename( $source_dir ) ); mkdir( $target_dir ) or die $! if !-d $target_dir; find ( \&wanted, $source_dir ); sub wanted { my $new_dir = '/'; $new_dir = $1 if $File::Find::dir =~ m|^$source_dir(.+)$|; $new_dir = catdir( $target_dir, $new_dir ); mkdir( $new_dir ) or die $! if ! -d $new_dir; copy ( $_, $new_dir ) or die $! if -f $_; }