Thread Verzeichnis kopieren (16 answers)
Opened by shaihulud at 2006-10-10 16:38

esskar
 2006-10-10 18:39
#70661 #70661
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
wohl irgendwie so!

Code: (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
use File::Copy ();

sub copy_recursive {
  my ($src, $dst) = map { noslashatend( dos2unix($_) ) } @_;
  die "Not a directory" unless -d $src;
  mkdir $dst;
 
  if(opendir(my $dir, $src)) {
     while(my $file = readdir $dir) {
        next if $file =~ m!^\.\.?$!;
       
        my $srcpath = "$src/$file";
        my $dstpath = "$dst/$file";
        if(-d $srcpath) {
           copy_recursive( $srcpath, $dstpath );
        } else {
           File::Copy::copy( $srcpath, $dstpath );
        }
     }
     closedir $dir;
  }
}

sub noslashatend {
  my $path = shift || '';
  $path =~ s!/+$!;
  return $path;
}

sub dos2unix {
 my $path = shift || '';
 $path =~ s!\\!/!g;
 return $path;
}


anwendung:
Code: (dl )
copy_recursive("c:\\foo", "c:\\bar");
\n\n

<!--EDIT|esskar|1160497122-->

View full thread Verzeichnis kopieren