Last active
August 29, 2015 14:04
-
-
Save shouhei/ab999cfdbe2ccf006181 to your computer and use it in GitHub Desktop.
ファイルを移動してリネームする。CLIからの第一引数が移動先でのファイル名、第二引数が移動対象の拡張子
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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