I expect that none of you really care about this or will run into this problem, but y'all were so helpful as I wandered on my fool's errand I'd like to share the end result of it. You might be amused at the way I got rid of the Unicode characters.. :o)
#!/usr/bin/perl
# Remove the Unicode characters from file names
# $Id: removeunicode.pl 1.2 2023/01/07 00:21:49 bernie Exp $
use v5.10 ;
use strict;
use warnings ;
use Getopt::Std ; # getopts(<flags>, \%args) ;
my %args ;
use Win32::LongPath ;
getopts("v", \%args) or Usage();
sub Usage
{ die "Usage: removeunicode [-v] <DIR>\n" ; }
my $dir = $ARGV[0] ;
Usage() unless $dir ;
chdir $dir or die "can't connect to $dir: $!\n" ;
trace("connected to $dir") ;
my $d = Win32::LongPath->new() ;
$d->opendirL(".") or die "Can't open $dir: $!\n" ;
for my $file ($d->readdirL($d))
{ my $fixedfile = sanitize($file) ;
next if $fixedfile eq $file ; # No unicode this filename
trace("working on $file") ;
trace("changing to $fixedfile") ;
renameL($file, $fixedfile) or die "didn't rename! $!";
}
exit ;
#Remove all the unicode characters from a string
sub sanitize
{ my $unicode = $_[0] ;
my $ascii ;
for my $char (split(//, $unicode))
{ $ascii .= $char if ord($char) < 256 }
return $ascii;
}
sub trace
{ say $_[0] if $args{v} }
|