trunk
Last change
on this file since 44957a5 was
44957a5,
checked in by mitty <mitty@…>, 11 years ago
|
- find file or directory that name contains Simplified Chinese characters
- output how to convert them to Japanese Shinjitai
git-svn-id: https://lab.mitty.jp/svn/lab/trunk@198 7d2118f6-f56c-43e7-95a2-4bb3031d96e7
|
-
Property mode set to
100755
|
File size:
1.1 KB
|
Rev | Line | |
---|
[44957a5] | 1 | #! /usr/bin/perl -w |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use utf8; |
---|
| 6 | |
---|
| 7 | use Encode; |
---|
| 8 | use Kanconvit; # http://kanconvit.ta2o.net/ |
---|
| 9 | |
---|
| 10 | my $top = shift @ARGV || exit; |
---|
| 11 | if (! -d $top) { exit; } |
---|
| 12 | |
---|
| 13 | my $utf8 = find_encoding("utf8"); |
---|
| 14 | my $ck = Kanconvit->new(); |
---|
| 15 | |
---|
| 16 | checkdir($top); |
---|
| 17 | |
---|
| 18 | sub match { |
---|
| 19 | my $str = shift @_; |
---|
| 20 | |
---|
| 21 | $str = $utf8->decode($str); |
---|
| 22 | my $jtext = $ck->conv_c2j($str); |
---|
| 23 | if ($str ne $jtext) { |
---|
| 24 | return $utf8->encode($jtext); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | return ''; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | sub checkdir { |
---|
| 31 | my $target = shift @_; |
---|
| 32 | |
---|
| 33 | print STDERR "# checking '$target'\n"; |
---|
| 34 | opendir(my $dir, $target) || return $target; |
---|
| 35 | my @entries = sort grep { !m/^(\.|\.\.)$/g } readdir($dir); |
---|
| 36 | closedir($dir); |
---|
| 37 | |
---|
| 38 | my @dirs; |
---|
| 39 | while (my $entry = shift @entries) { |
---|
| 40 | if (my $japanese = match($entry)) { |
---|
| 41 | print "mv '$target/$entry' \\\n"; |
---|
| 42 | print " '$target/$japanese'\n"; |
---|
| 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.