将目录复制到目标文件夹

时间:2017-12-07 10:02:36

标签: perl

我编写了一个Perl脚本,它分割目录列表并将它们复制到目标文件夹。

这是我的代码

#! /usr/bin/perl

#use strict;
use warnings;

use File::Copy;
use File::Copy::Recursive qw (dircopy);

#Usage:

#Test.pl     [-fixUrl] [-ver=<fn>]
#   If the -fixurl option is present, copy the files to destination folder
#   The -ver option to define the file that contains the version of the app
#END

my $source_dir  = "C:\Users\name\Desktop\test, C:\Users\name\Desktop\perl/test1";
my $target_dir  = "D:/Project/Application/UAT";
my $file_format = "csv.txt";
my $app_name    = "TestApp";

my ( $buildno, $ver ) = @ARGV;

$Artifact_name = "TestDrive_$app_name-$buildno\_Ver\_$ver";
mkdir "$target_dir/$Artifact_name";

my @list     = split( ',', $source_dir );
my @filelist = split( ',', $file_format );

for ( my $i = 0; $i < @list; $i++ ) {

    my $dir_val          = @list[$i];
    my $file_formmat_val = @filelist[$i];

    opendir( my $DIR, $dir_val ) || die "can't opendir $DIR: $!";
    my @files = readdir( $DIR );

    print "the directories list : @list \n";
    print "file format value: $file_formmat_val \n";
    print "file list: @files \n";

    # Here i want to copy the both Source directories
    # to Target Directory with file format csv and txt files.*
}

你能告诉我们如何实现这个目标吗?

另外,我想像这样运行Test.pl脚本

Test.Pl fixUrl ver=ver.txt

我会很高兴解决方案。

0 个答案:

没有答案