File: copy_with_ext.pl

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-5
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 35,880 kB
  • sloc: cs: 160,836; java: 42,449; cpp: 7,605; ansic: 1,728; perl: 1,087; makefile: 236; php: 142; xml: 117; sh: 21
file content (21 lines) | stat: -rw-r--r-- 566 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/perl
use File::Copy;

my $srcdir = $ARGV[0];
my $dstdir = $ARGV[1];
my $ext = $ARGV[2];

opendir DH, $srcdir or die "$srcdir:$!";
while( my $file = readdir DH ){
    next if $file =~ /^\.{1,2}$/; #skip '.' and '..'
    my $indx = rindex( $file, $ext );
    if( $indx == length( $file ) - length( $ext ) ){
        my $srcfile = $srcdir . $file;
        my $dstfile = $dstdir . $file;
        my $srcfile_size = -s $srcfile;
        if( $srcfile_size > 0 ){
            copy( $srcfile, $dstfile ) or die $!;
        }
    }
}
closedir DH;