IllustratorPackageのWindows版をPerlで作成中
Revision | d9a9ae8a3cab2320ccd6b9667cb3b10e4e91e47a (tree) |
---|---|
Time | 2012-10-09 14:51:54 |
Author | ![]() |
Commiter | macneko_ayu |
IllustratorPackage_perl.pl modified. $file's value changed command prompt argument.
@@ -3,15 +3,15 @@ use warnings; | ||
3 | 3 | use utf8; |
4 | 4 | use Encode qw/decode encode/; |
5 | 5 | use File::Basename; #ファイルパス分割のため |
6 | -#use File::Spec; #ファイルパス結合のため | |
7 | 6 | use File::Copy; #ファイルコピーのため |
8 | 7 | |
9 | 8 | # ファイルシステムの設定(デフォルト:Unix) |
10 | 9 | fileparse_set_fstype('MSWin32'); |
11 | 10 | |
12 | 11 | my $temp = ""; |
13 | -my $file = "C:/CS4_Test/ごん太.ai"; | |
12 | +my $file = $ARGV[0]; | |
14 | 13 | my @linkfilepath = ($file); #収集するファイルのパスを入れる配列 |
14 | +my $errcount = 0; | |
15 | 15 | |
16 | 16 | #デスクトップに現在時刻名のディレクトリを作成 |
17 | 17 | sub mkdir_localtime { |
@@ -21,11 +21,11 @@ sub mkdir_localtime { | ||
21 | 21 | my $time = "$year-$mon-$mday $hour-$min-$sec"; |
22 | 22 | mkdir $ENV{USERPROFILE}.encode('CP932','/デスクトップ/').$time |
23 | 23 | or die "Can't make dir: $!"; |
24 | - return $ENV{USERPROFILE}.'/デスクトップ/'.$time; #戻り値はエンコードしない | |
24 | + return $ENV{USERPROFILE}.'/デスクトップ/'.$time; #戻り値はencodeしない | |
25 | 25 | } |
26 | 26 | |
27 | -open my $fh, '<', encode('CP932',$file) | |
28 | - or die "can't open $file: $!"; | |
27 | +open my $fh, '<', $file | |
28 | + or die "Can't open $file: $!"; | |
29 | 29 | |
30 | 30 | while (my $line = <$fh>) { |
31 | 31 | if ($line =~/Adobe Illustrator CS2/){ |
@@ -41,27 +41,36 @@ close $fh; #開いたら閉じる | ||
41 | 41 | |
42 | 42 | if ($#linkfilepath > -1) { #配列が空じゃなかったら |
43 | 43 | my $newdir = mkdir_localtime(); |
44 | - my $newdir_CP932 = encode('CP932', $newdir); #エンコードした変数を準備 | |
44 | + my $newdir_CP932 = encode('CP932', $newdir); #encodeした変数を準備 | |
45 | 45 | |
46 | 46 | foreach my $item (@linkfilepath){ |
47 | - my $item_CP932 = encode('CP932', $item); #エンコードした変数を準備 | |
47 | + my $item_CP932 = encode('CP932', $item); #encodeした変数を準備 | |
48 | 48 | |
49 | - if (-f $item_CP932){ #ファイルが存在していたら(-fでファイルの存在確認) | |
49 | + if (-f $item_CP932){ #encode_CP932した結果ファイルが存在していたら(-fでファイルの存在確認) | |
50 | 50 | unless (copy($item_CP932, $newdir_CP932)){ #copyに失敗したら |
51 | - print "can't copy from \"$item_CP932\" to \"".$newdir_CP932."\": $!"; | |
51 | + print "Can't copy from \"$item_CP932\" to \"".$newdir_CP932."\": $!"; | |
52 | 52 | } |
53 | - } else { | |
53 | + } elsif (-f $item){ #encode_CP932しないでファイルが存在していたら | |
54 | + unless (copy($item, $newdir_CP932)){ #copyに失敗したら | |
55 | + print "Can't copy from \"$item\" to \"".$newdir_CP932."\": $!"; | |
56 | + } | |
57 | + | |
58 | + } else { #ファイルが存在しなかったらIlustratorファイル直下から探す | |
54 | 59 | my $filedir = dirname($file); #Illustratorファイルの親ディレクトリ取得 |
55 | 60 | my $linkpath = basename($item); #配置ファイルの名前を取得 |
56 | -# my $linkfile = File::Spec->catfile($filedir, $linkpath); #結合してファイルパスにする | |
57 | 61 | my $linkfile = $filedir."/".$linkpath; #結合してファイルパスにする |
58 | - $linkfile = decode('utf8', $linkfile); #内部文字列(utf8)にデコードする | |
62 | + $linkfile = decode('utf8', $linkfile); #内部文字列(utf8)にdecodeする | |
59 | 63 | my $linkfile_CP932 = encode('CP932',$linkfile); |
60 | 64 | unless (copy($linkfile_CP932, $newdir_CP932)){ |
61 | - print "can't copy from \"$linkfile_CP932\" to \"$newdir_CP932\" "; | |
65 | + print "Can't copy from \"$linkfile_CP932\" to \"$newdir_CP932\" "; | |
66 | + $errcount ++; | |
62 | 67 | } |
63 | 68 | } |
64 | 69 | } |
65 | 70 | } |
66 | 71 | |
67 | -print "successful!"; | |
72 | +if ($errcount == 0){ | |
73 | + print "Successful!"; | |
74 | +} else { | |
75 | + print "Done! but can't collected files : $errcount files"; | |
76 | +} | |
\ No newline at end of file |