0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

任意のディレクトリ配下にあるp5のjarファイルを一括コピーする

Posted at

毎回コピーするのが面倒なのでスクリプト化してみた

想定するディレクトリ構成( 例: /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;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?