Picasa Peep
The more I use Picasa 2, the more I am amazed by it. But I ran into one hitch today: it doesn’t process files whose filenames contain multibyte characters. This limitation is alluded to by an entry in the Picasa 2 Knowledge Base. I have at least one CD of more than 300 images all of the form 照片 xxx.jpg where xxx is a three digit number. Chinese characters … trouble!
Instead of renaming them by hand (never!) I wrote a perl script that would do it for me. It’s been awhile since I’ve programmed anything … any practice I get from here on in is constructive! My perl also usually isn’t written in Notepad for use in Windows - necessary this time because I am using Lesley’s computer (I seem to have ransomed all the hard drive space on my own, which doesn’t bode well for image processing!). I was puzzled that it was crapping out in the copy step until I realized I needed to pass the -C flag to the interpreter. Sweet!
#!F:\Perl\bin\perl.exe -C
# must use the "-C" flag to specify native wide
# character system calls
use strict;
use File::Spec;
use File::Copy;
my $progname = "rmchinese.pl";
unless (@ARGV) {
print "Usage: $progname [directory]\n";
print "Copies any file in chosen directory whose\n";
print "filename contains a three digit number with\n";
print "the preceding characters (presumably\n";
print "multibyte, i.e. Chinese) removed.\n";
print "\n";
print " not007.bak => 007.bak\n";
print " 101foo.jpg => 101foo.jpg\n";
print " b747ar.ogg => 747ar.ogg\n";
print " 112358.sxw => 112358.sxw\n";
}
foreach my $dir (@ARGV) {
print "Checking files in $dir\n";
opendir(DIR, $dir)
or die ("Could not open directory: $!");
my @files = readdir(DIR);
foreach my $file (@files) {
if ($file =~ /.*?([0-9]{3}.*)/) {
if ($file ne $1) {
my $orig = File::Spec->catfile($dir, $file);
my $copy = File::Spec->catfile($dir, $1);
copy ($orig, $copy)
or die ("Rename failed: $!");
print "Created $copy\n";
}
}
}
closedir(DIR);
}