What conversion do I need to perform on a file name that contains non-ASCII characters so that I can pass it to MP3::Info::get_mp3info? The code below prints "<file name>: File is empty" for files containing non-ASCII characters (e.g. "Blue Öyster Cult- (Don't Fear) The Reaper".) I want to know how to use the file names produced by console programs, so please no suggestions to rewrite the script so that it uses a completely different method to get the file names. Thanks. Update 4:08PM: I found that converting the file name to a short name with Win32::GetShortPathName and passing the short file name to get_mp3info appears to work correctly, EVEN IF THE SHORT NAME ALSO HAS NON-ASCII CHARACTERS IN IT! (CDBurnerXP generates short names with those characteristics.) There seems to be something about long file names containing non-ASCII characters that makes get_mp3info unable to open the file.

use strict; use warnings; use Encode; use MP3::Info; my $dir = ''; binmode STDOUT, ":encoding(UTF-8)"; for my $rawline (`dir /s $ARGV[0]`) { chop($rawline); # remove newline my $line = decode('cp437', $rawline); if ($line =~ /^\d/ && substr($line, 24, 1) eq ' ') { # listing for a file, not a directory my $extix = rindex($line, '.'); my $filename = substr($line, 39); my $filepath = "$dir\\$filename"; my $mp3time = ''; if (lc(substr($line, $extix, 3)) eq '.mp') { # mpeg file my $info = get_mp3info($filepath); if (defined($info)) { print "$filepath: time is $info->{TIME}\n"; } else { print("$filepath: $@\n"); } } } elsif (substr($line, 0, 14) eq ' Directory of ') { $dir = substr($line, 14); $dir =~ s/\\$//; print("$line\n"); } }

In reply to How to use get_mp3info() by freonpsandoz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.