以前のメモ(テンプレートファイルを開いているフォルダにコピー(回りくどいけど楽に安全に) - Toolbox)について、Perl/Tkx版のテンプレートファイル選択ダイアログを作った。
copy_template.plを下記のコードで差し替えればOK。
2012/12/05 コピー先パスが日本語でも大丈夫なように修正。
use utf8; use strict; use Encode; use Tkx; use File::Basename; use File::Copy; # 雛形ファイルの置き場。 # セパレータは\\にしないと動作しない。 # 末尾の\\がないと2回目以降最後に開いたフォルダが開かれてしまう。 my $TemplateDir = "C:\\home\\templates\\"; my $target_dir = dirname($ARGV[0]); my $top = Tkx::widget->new("."); $top->g_wm_withdraw(); my $template_file = Tkx::tk___getOpenFile( -parent=>$top, -initialdir=>"$TemplateDir", -title=>'コピーするテンプレートを選択'); if($template_file) { copy(encode('cp932', $template_file), $target_dir); } # EOF
ActivePerl 5.14で動作確認。