「表」というファイルを作成して、 -d で結果を取得するとファイルなのにディレクトリと判定されてしまいます。
opendir()も成功してしまいます。文字コードまわりの処理は正しく書いたつもりなのですが。。。
ファイル名を「あ」とした場合は問題ありません。
正しく判定できる方法を教えてください。Win32::OLEなどを利用した方法でもかまいません。
--- ソース ---
use Encode;
use utf8;
use strict;
my $ENCODING = 'cp932';
binmode(STDIN,":encoding($ENCODING)") ;
binmode(STDOUT,":encoding($ENCODING)") ;
binmode(STDERR,":encoding($ENCODING)") ;
my $dir = "C:\\表"; #「表」っていうファイルはある
# ディレクトリかどうか?
if (-d encode($ENCODING, $dir)) {
print "FOUND DIR ". $dir ."\n";
} else {
print "NOT FOUND DIR\n";
}
# ファイルかどうか?
if (-f encode($ENCODING, $dir)) {
print "FOUND FILE". $dir ."\n";
} else {
print "NOT EXISTS \n";
}
# opendirしてみる
opendir(DIR, encode($ENCODING, $dir)) or die $!;
while (my $file = readdir(DIR)) {
$file = decode($ENCODING, $file);
print "FILE: ".$file."\n";
}
--- 結果 ---
FOUND DIR C:\表
NOT EXISTS
FILE: 表
--- 環境 ---
Win XP SP3
ActivePerl 5.10.0 Build 1005
コメント(0件)