Last change
on this file since 198 was
198,
checked in by mitty, 11 years ago
|
- find file or directory that name contains Simplified Chinese characters
- output how to convert them to Japanese Shinjitai
|
-
Property svn:executable set to
*
|
File size:
1.1 KB
|
Rev | Line | |
---|
[187] | 1 | #! /usr/bin/perl -w |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use utf8; |
---|
| 6 | |
---|
[192] | 7 | use Encode; |
---|
[198] | 8 | use Kanconvit; # http://kanconvit.ta2o.net/ |
---|
[187] | 9 | |
---|
| 10 | my $top = shift @ARGV || exit; |
---|
| 11 | if (! -d $top) { exit; } |
---|
| 12 | |
---|
[192] | 13 | my $utf8 = find_encoding("utf8"); |
---|
[198] | 14 | my $ck = Kanconvit->new(); |
---|
[192] | 15 | |
---|
[187] | 16 | checkdir($top); |
---|
| 17 | |
---|
[188] | 18 | sub match { |
---|
[187] | 19 | my $str = shift @_; |
---|
| 20 | |
---|
[194] | 21 | $str = $utf8->decode($str); |
---|
[198] | 22 | my $jtext = $ck->conv_c2j($str); |
---|
| 23 | if ($str ne $jtext) { |
---|
| 24 | return $utf8->encode($jtext); |
---|
[187] | 25 | } |
---|
| 26 | |
---|
| 27 | return ''; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | sub checkdir { |
---|
| 31 | my $target = shift @_; |
---|
| 32 | |
---|
[195] | 33 | print STDERR "# checking '$target'\n"; |
---|
[187] | 34 | opendir(my $dir, $target) || return $target; |
---|
[193] | 35 | my @entries = sort grep { !m/^(\.|\.\.)$/g } readdir($dir); |
---|
[187] | 36 | closedir($dir); |
---|
| 37 | |
---|
| 38 | my @dirs; |
---|
| 39 | while (my $entry = shift @entries) { |
---|
[198] | 40 | if (my $japanese = match($entry)) { |
---|
| 41 | print "mv '$target/$entry' \\\n"; |
---|
| 42 | print " '$target/$japanese'\n"; |
---|
[187] | 43 | next; |
---|
| 44 | } |
---|
| 45 | if (-d "$target/$entry") { |
---|
| 46 | push @dirs, $entry; |
---|
| 47 | next; |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | while (my $entry = pop @dirs) { |
---|
| 52 | checkdir("$target/$entry"); |
---|
| 53 | } |
---|
| 54 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.