Even using wildcards fails sometimes. Here's something I wrote years ago. It's meant for tweaking
when you run across a nasty file or directory name, so it won't solve your problem without a little work.
The foreach loop at the bottom is to print out non-printable characters are their ordinal value, which
is invaluable when you can't figure out what's going on. The trick is not trying to handle the names
in a shell at all. Even perl can fail in this regard using rename and unlink. I may have something to
do with invoking a shell anyway when there are shell variables in the name, but that's what the added
backslashes are supposed to prevent.
Chris
#!/usr/bin/perl -w
# adjust as necessary. This was written to delete a dir that included a 0xA (\n)
# and square brackets in the actual name, so it was really tough to handle from the shell.
opendir(DIR, '.');
while(defined($dir_ent=readdir(DIR))) {
#next if ( $dir_ent !~ /GetSubrDir/ );
print " \$dir_ent [$dir_ent]\n";
$dir_ent =~ s/([\[])/\\$1/g; # '\' protect the brackets so they aren't handled as special shell things
$dir_ent =~ s/([\]])/\\$1/g;
print " \$dir_ent [$dir_ent]\n";
# rename( $dir_ent, 'bad_dir' ) or print "failed to rename: $!\n";
@chars = split('',$dir_ent); # the split is on a pair of single quotes with no space; you get a list of individual characters
foreach $char(@chars) {
$ord=ord($char);
#print " \$ord [$ord], \$char [$char]\n";
}
}