毎回コピーするのが面倒なのでスクリプト化してみた
想定するディレクトリ構成( 例: /usr/local/hogehoge/p5/ )
/
|--artnet4j2
| |--library
| | |--artnet4j2.jar
|--oscp5
| |--library
| | |--oscp5.jar
ソースコード
copyP5Lib.pl
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use Smart::Options;
use File::Find::Rule;
use File::Copy qw/copy move/;
use File::Basename;
# p5のjarを保存しているディレクトリ
my $source_dir_path = "/usr/local/hogehoge/p5/";
my $argv = Smart::Options->new->parse;
unless (defined($argv->{'target_dir'})) {
print 'usage: $ perl copyP5Lib.pl --target_dir=[path/to/dir]', $/;
exit;
}
my $target_dir = $argv->{'target_dir'};
unless (-d $target_dir) {
print 'target_dir: "', $target_dir, '" does not exists. exit.', $/;
exit;
}
my @jar_files = File::Find::Rule->file
->name('*.jar')
->in($source_dir_path);
foreach my $jar_file_path(@jar_files) {
if ($jar_file_path =~ /.*\/library\/.*\.jar/) {
my $jar_filename = basename($jar_file_path);
# print $jar_filename, $/;
if (-e join("/", ($target_dir, $jar_filename))) {
print "[warn] ", $jar_filename, " has already exits.", $/;
}
copy $jar_file_path, $target_dir;
print "[copy] ", $jar_file_path, $/;
}
}
exit;