If you don't know how to use the information that comes out of that, post a reply with a few examples of the output for non-ASCII file names (look for lines containing hex numerics greater than " 7f ").#!/usr/bin/perl use strict; use warnings; (@ARGV == 1 and -d $ARGV[0]) or die "Usage: $0 pathname\n"; my $dir = shift; opendir( DIR, $dir ) or die "$dir: $!"; while ( $_ = readdir DIR ) { next if ( /^\.\.?$/ ); print join( " ", map { sprintf( " %02x", ord($_)) } split //, $_ ) +; if ( -f ) { open( I, $_ ) or do { warn "$_: $!"; next }; my $sum = 0; $sum += length() while (<I>); close I; printf( " : %d bytes (%d read)\n", -s _, $sum ); } elsif ( -d _ ) { print " : directory\n"; } else { print " : not sure what this is\n" } }
You might also want to take a bunch of these odd-ball file names (as fetched by readdir) and concatenate them (with spaces between them) into a single long string, and pass that to the "guess_encoding" function provided by Encode::Guess -- if the characters really are non-unicode Asian or some form of unicode, there's a good chance it'll give you a correct answer, which you can then use with Encode's "decode" function, to turn the strings into perl-internal utf8 (in case that's helpful for anything).
In reply to Re: Opening files with japanese/chinese chars in filename
by graff
in thread Opening files with japanese/chinese chars in filename
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |