开发者

Perl recursive file search for unicode filenames

I've tried File::Find::Rule, but it doesn't reveal filenames that contain characters like: בר רפאלי

Any ideas?

use File::Find::Rule;
use Win32::Shortcut;
use Spreadsheet::Writ开发者_StackOverflow社区eExcel;

my $workbook  = Spreadsheet::WriteExcel->new('status.xls');

my $worksheet = $workbook->add_worksheet();


my $base_dir ='E:/files/';

my $find_rule = File::Find::Rule->new;

#$find_rule->maxdepth(1);

$find_rule->name('*.lnk');

my @files = $find_rule->in($base_dir);

print scalar(@files)."\n";

#print join("\n", @files);


I have no way to test this (Linux, not too much Unicode knowledge etc) and its probably inefficient, but perhaps it will work in a "just get it done kind of way. You could use my File::chdir::WalkDir and use a per-file callback that adds to the file name to a list:

#!/usr/bin/env perl

use strict;
use warnings;

use File::chdir::WalkDir;
use File::Spec::Functions 'catfile';

my $base_dir = '.';

my @files;
my $callback = sub {
  my ($file, $dir) = @_;
  return unless ($file =~ /\.lnk$/);

  push @files, catfile($dir, $file);
};

walkdir($base_dir, $callback);

Since this leans on opendir and friends it may be slow, but as long as it can see your files, this should work. Give it a try and let me know if there are problems.


see Win32::Unicode::Native and http://perlmonks.com/?node_id=843602

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜