-
=info
-
遍历目录树 支持 Unicode
-
Code by 523066680@163.com
-
2017-03
-
-
V0.5 使用Win32API判断目录硬链接
-
=cut
-
-
use utf8;
-
use Encode;
-
use Win32API::File qw(GetFileAttributesW FILE_ATTRIBUTE_REPARSE_POINT);
-
use Win32::Unicode;
-
use IO::Handle;
-
STDOUT->autoflush(1);
-
binmode(STDOUT, ‘:encoding(gbk)‘);
-
-
our $n_files = 0;
-
our $n_dirs = 0;
-
-
my $path = "D:/Extra";
-
func($path, 0);
-
-
print $n_files ,"\n";
-
print $n_dirs;
-
-
sub func
-
{
-
my ($path, $lv) = (shift, shift);
-
my $wdir = Win32::Unicode::Dir->new;
-
my $code;
-
my $next_path;
-
-
$wdir->open( $path );
-
if ( $wdir->error() =~ /找不到/ )
-
{
-
print $wdir->error();
-
exit;
-
}
-
-
while ( my $f = $wdir->read() )
-
{
-
if ( file_type(‘f‘, $path. "/" .$f ) )
-
{
-
print " "x$lv . "$f\n";
-
$n_files++;
-
}
-
-
next if ($f eq ".");
-
next if ($f eq "..");
-
-
$next_path = $path. "/" .$f;
-
-
if ( file_type(‘d‘, $next_path ) )
-
{
-
$n_dirs++;
-
print " "x$lv . "$f\n";
-
$code = GetFileAttributesW( encode(‘utf16-le‘, $next_path) ."\x00\x00" );
-
-
if ( isLink( $code ) ) { print "skip symbolic link: $f\n"; }
-
else { func( $next_path, $lv+1 ); }
-
}
-
-
}
-
}
-
-
sub isLink
-
{
-
return ($_[0] & FILE_ATTRIBUTE_REPARSE_POINT) == FILE_ATTRIBUTE_REPARSE_POINT ?
-
1 : 0;
-
}
遍历目录树 - Unicode 模式
Posted catgatp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了遍历目录树 - Unicode 模式相关的知识,希望对你有一定的参考价值。
以上是关于遍历目录树 - Unicode 模式的主要内容,如果未能解决你的问题,请参考以下文章