Thread Verzeichnis kopieren inkl. Files & Unterordner (5 answers)
Opened by PETER_PAN2009 at 2010-02-19 12:11

Gast Gast
 2010-02-20 09:32
#133361 #133361
Nur mit Core-Modulen:

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
#!/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 $_;
}

View full thread Verzeichnis kopieren inkl. Files & Unterordner