#!/usr/local/bin/perl # rcleanbidi.pl # ``modified by Mickey london from the original pyton script # of Gabi Danon, 14/2/2002 # Last updated on 14/5/2002 # # This script removes the Unicode directionality charcters LRO # (0x202D), RLO (0x202E) and PDF (0x202C) from names of files in the # current directory. This speeds up the Finder in Mac OS X 10.1.2 on # many disks which were used under Mac OS 9.x and earlier with the # Hebrew language kit. # # This script must be run from the command line in Terminal, using the # Unix version of Perl. # For more details, see: # http://homepage.mac.com/gabidanon/cleanbidi.html # The script by default do not change the lock property (in Finder) of # files and thus fails to rename some files. If you like to unlock # files and rename them use the command line argument: # '+allow_locked_files" $total_renamed = 0; # Counter for number of files renamed $unlock = 0; # flag if unlocking files is permitted $errlog = 0; # Counter for files that falied to be renamed $i = 0; if ($#ARGV > -1) { if ($ARGV[$i] =~ /^\+allow_locked_files$/) { print STDOUT "Locked files are alowed\n"; $unlock = 1; $i++; } } # the following finds all the files under the directory # and pipe them through the file handler FN open(FN,"find . -print |"); open(LOG,">/tmp/cleanbidi.log") || die "can't open log file /tmp/cleanbidi.log"; open(ERRORLOG,">/tmp/cleanbidi.err") || die "can't open log file /tmp/cleanbidi.err"; print LOG "This file contains the files that were renamed\n"; print LOG "++++++++++++++++++++++++++++++++++++++++++++++\n"; print ERRORLOG "This file contains the files that could not been renamed\n\n"; print ERRORLOG "Please check the permision of these files, or thier LOCK property\n"; print ERRORLOG "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"; while ($fn = ){ chop($fn); ($fn1 = $fn) =~ s/\xe2\x80\xad//g; ($fn2 = $fn1) =~ s/\xe2\x80\xae//g; if (!($fn2 eq $fn) ) { ($fn3 = $fn2) =~ s/\xe2\x80\xac//g; if (! rename($fn,$fn3) ) { if ($unlock) { if (! system("/Developer/Tools/SetFile -a l $fn3") ) { print ERRORLOG "Could not rename nor unlock: $fn\n"; $errlog++; } else { # try again if (! rename($fn,$fn3) ) { print ERRORLOG "Unlocking did not help for file $fn\n"; $errlog++; system("/Developer/Tools/SetFile -a L $fn"); # Lock it back } else { system("/Developer/Tools/SetFile -a L $fn3"); # Lock the file with the new filename } } } else { #Unlocking is not permitted print ERRORLOG "Could not rename $fn\n"; $errlog++; } } $total_renamed++; print LOG "Rename:\t",$fn,"\n\t--->\t",$fn3,"\n"; print STDOUT "Rename:",$fn," \t",$fn3,"\n"; } } print STDOUT "Successfully Renamed:",$total_renamed,"\n"; print STDOUT "Unable to renamed:",$errlog,"\n"; print STDOUT "See /tmp/cleanbidi.log and /tmp/cleanbidi.err for details!",$errlog,"\n";