perl 文件夹及文件操作

#!/usr/bin/perl -w
use strict;
use warnings;
use File::Copy;


my $usage=<<USAGE;
Usage:
    perl dz_putFiles2oneDir.pl /path/to/input_dir /path/to/filename
USAGE
if(@ARGV==0){die $usage};

my $file1=$ARGV[0];
my $file2=$ARGV[1];

my $input_dir=$file1;
my $output=$file2;

opendir(DIR,$input_dir) || die "can not open the directory";
if(!(-d $output)){
    mkdir ($output); #创建文件夹
}
if((-d $input_dir) && ($input_dir ne $output)){
    my @files=glob($input_dir."/*/*.gz");
    for my $i (0..$#files){
        copy ($files[$i],$output) || die "Copy failed: $!";
    }
}

closedir(DIR);
此条目发表在Perl分类目录。将固定链接加入收藏夹。

发表评论

邮箱地址不会被公开。 必填项已用*标注

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Protected with IP Blacklist CloudIP Blacklist Cloud