IllustratorPackageのWindows版をPerlで作成中
Revision | b40940ac00b4a36e40f616d5a887c011f9acb962 (tree) |
---|---|
Time | 2012-10-16 18:08:20 |
Author | ![]() |
Commiter | macneko_ayu |
Oldversion IllustratorPackage_perl.pl deleted.
@@ -1,76 +0,0 @@ | ||
1 | -use strict; | |
2 | -use warnings; | |
3 | -use utf8; | |
4 | -use Encode qw/decode encode/; | |
5 | -use File::Basename; #ファイルパス分割のため | |
6 | -use File::Copy; #ファイルコピーのため | |
7 | - | |
8 | -# ファイルシステムの設定(デフォルト:Unix) | |
9 | -fileparse_set_fstype('MSWin32'); | |
10 | - | |
11 | -my $temp = ""; | |
12 | -my $file = $ARGV[0]; | |
13 | -my @linkfilepath = ($file); #収集するファイルのパスを入れる配列 | |
14 | -my $errcount = 0; | |
15 | - | |
16 | -#デスクトップに現在時刻名のディレクトリを作成 | |
17 | -sub mkdir_localtime { | |
18 | - my ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime(); | |
19 | - $year += 1900; | |
20 | - $mon += 1; | |
21 | - my $time = "$year-$mon-$mday $hour-$min-$sec"; | |
22 | - mkdir $ENV{USERPROFILE}.encode('CP932','/デスクトップ/').$time | |
23 | - or die "Can't make dir: $!"; | |
24 | - return $ENV{USERPROFILE}.'/デスクトップ/'.$time; #戻り値はencodeしない | |
25 | -} | |
26 | - | |
27 | -open my $fh, '<', $file | |
28 | - or die "Can't open $file: $!"; | |
29 | - | |
30 | -while (my $line = <$fh>) { | |
31 | - if ($line =~/Adobe Illustrator CS2/){ | |
32 | - die "this file maked Adobe Illustrator CS2." | |
33 | - } elsif ($line =~ /^<\/x:xmpmeta>/ ){ | |
34 | - last | |
35 | - } elsif ($line =~ /^\s+?<stRef:filePath>(.+?)<\/stRef:filePath>/) { | |
36 | - push(@linkfilepath,$1); | |
37 | - } | |
38 | -} | |
39 | - | |
40 | -close $fh; #開いたら閉じる | |
41 | - | |
42 | -if ($#linkfilepath > -1) { #配列が空じゃなかったら | |
43 | - my $newdir = mkdir_localtime(); | |
44 | - my $newdir_CP932 = encode('CP932', $newdir); #encodeした変数を準備 | |
45 | - | |
46 | - foreach my $item (@linkfilepath){ | |
47 | - my $item_CP932 = encode('CP932', $item); #encodeした変数を準備 | |
48 | - | |
49 | - if (-f $item_CP932){ #encode_CP932した結果ファイルが存在していたら(-fでファイルの存在確認) | |
50 | - unless (copy($item_CP932, $newdir_CP932)){ #copyに失敗したら | |
51 | - print "Can't copy from \"$item_CP932\" to \"".$newdir_CP932."\": $!"; | |
52 | - } | |
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ファイル直下から探す | |
59 | - my $filedir = dirname($file); #Illustratorファイルの親ディレクトリ取得 | |
60 | - my $linkpath = basename($item); #配置ファイルの名前を取得 | |
61 | - my $linkfile = $filedir."/".$linkpath; #結合してファイルパスにする | |
62 | - $linkfile = decode('utf8', $linkfile); #内部文字列(utf8)にdecodeする | |
63 | - my $linkfile_CP932 = encode('CP932',$linkfile); | |
64 | - unless (copy($linkfile_CP932, $newdir_CP932)){ | |
65 | - print "Can't copy from \"$linkfile_CP932\" to \"$newdir_CP932\" "; | |
66 | - $errcount ++; | |
67 | - } | |
68 | - } | |
69 | - } | |
70 | -} | |
71 | - | |
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 |