source: lab.git/misc/findnonsjis.pl @ cdcfe90

trunk
Last change on this file since cdcfe90 was cdcfe90, checked in by mitty <mitty@…>, 11 years ago
  • find file or directory that name contains non sjis character

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

  • Property mode set to 100755
File size: 950 bytes
Line 
1#! /usr/bin/perl -w
2
3use strict;
4use warnings;
5use utf8;
6use encoding 'utf-8';
7
8use Unicode::Japanese qw(unijp);
9
10my $top = shift @ARGV || exit;
11if (! -d $top) { exit; }
12
13checkdir($top);
14
15sub match {
16    my $str = shift @_;
17   
18    my $sjis = unijp($str)->sjis;
19    if ($sjis =~ /&#\d{4,};/) {
20        return 1;
21    }
22   
23    return '';
24}
25
26sub checkdir {
27    my $target = shift @_;
28   
29    print STDERR "checking '$target'\n";
30    opendir(my $dir, $target) || return $target;
31    my @entries = sort readdir($dir);
32    closedir($dir);
33   
34    my @dirs;
35    while (my $entry = shift @entries) {
36        next if ($entry =~ /^\.+$/);
37        if (match($entry)) {
38            print "'$target/$entry' contains non Shift_JIS character\n";
39            next;
40        }
41        if (-d "$target/$entry") {
42            push @dirs, $entry;
43            next;
44        }
45    }
46   
47    while (my $entry = pop @dirs) {
48        checkdir("$target/$entry");
49    }
50}
Note: See TracBrowser for help on using the repository browser.