* find file or directory that name contains Simplified Chinese characters
authormitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Fri, 25 Jan 2013 16:57:12 +0000 (16:57 +0000)
committermitty <mitty@7d2118f6-f56c-43e7-95a2-4bb3031d96e7>
Fri, 25 Jan 2013 16:57:12 +0000 (16:57 +0000)
 * output how to convert them to Japanese Shinjitai

git-svn-id: https://lab.mitty.jp/svn/lab/trunk@198 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

misc/findsimplified.pl [new file with mode: 0755]

diff --git a/misc/findsimplified.pl b/misc/findsimplified.pl
new file mode 100755 (executable)
index 0000000..024e4cc
--- /dev/null
@@ -0,0 +1,54 @@
+#! /usr/bin/perl -w
+
+use strict;
+use warnings;
+use utf8;
+
+use Encode;
+use Kanconvit;  # http://kanconvit.ta2o.net/
+
+my $top = shift @ARGV || exit;
+if (! -d $top) { exit; }
+
+my $utf8 = find_encoding("utf8");
+my $ck = Kanconvit->new();
+
+checkdir($top);
+
+sub match {
+    my $str = shift @_;
+    
+    $str = $utf8->decode($str);
+    my $jtext = $ck->conv_c2j($str);
+    if ($str ne $jtext) {
+        return $utf8->encode($jtext);
+    }
+    
+    return '';
+}
+
+sub checkdir {
+    my $target = shift @_;
+    
+    print STDERR "# checking '$target'\n";
+    opendir(my $dir, $target) || return $target;
+    my @entries = sort grep { !m/^(\.|\.\.)$/g } readdir($dir);
+    closedir($dir);
+    
+    my @dirs;
+    while (my $entry = shift @entries) {
+        if (my $japanese = match($entry)) {
+            print "mv '$target/$entry' \\\n";
+            print "   '$target/$japanese'\n";
+            next;
+        }
+        if (-d "$target/$entry") {
+            push @dirs, $entry;
+            next;
+        }
+    }
+    
+    while (my $entry = pop @dirs) {
+        checkdir("$target/$entry");
+    }
+}