Skip to content

Instantly share code, notes, and snippets.

@shouhei
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save shouhei/ab999cfdbe2ccf006181 to your computer and use it in GitHub Desktop.

Select an option

Save shouhei/ab999cfdbe2ccf006181 to your computer and use it in GitHub Desktop.
ファイルを移動してリネームする。CLIからの第一引数が移動先でのファイル名、第二引数が移動対象の拡張子
#!/usr/bin/perl
binmode STDOUT,":utf8";
use strict;
use warnings;
use utf8;
use File::Copy;
my $class_name = $ARGV[0];
unless($class_name){
print "移動先でのファイル名を指定してください\n";
exit;
}
my $extension = $ARGV[1];
unless($extension){
print "移動対象の拡張子を指定してください\n";
exit;
}
while(<./*$extension>){
my $file = $_;
$_ =~ s/\.\///g;
$_ =~s/\.$extension//g;
mkdir $_;
move "./$file", "./$_/$class_name" or die $!;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment