<?php const FromEncoding = 'utf-8'; const ToEncoding = 'cp1251'; function convertEncoding($filename) { return mb_convert_encoding($filename, ToEncoding, FromEncoding); } function traverse($dir) { $handler = opendir($dir); if(!$handler) { echo ("\n* * *\tError: Cannot open directory ($dir)\n"); return 0; } echo "* * *\tENTERING: " . $dir . PHP_EOL; while($filename = readdir($handler)) { if($filename != '.' && $filename != '..') { echo $dir . '/' . $filename; $newName = convertEncoding($filename); rename($dir . '/' . $filename, $dir . '/' . $newName); echo "\n\t=>\t" . $newName . PHP_EOL; if(is_dir($dir . '/' . $newName)) { traverse($dir . '/' . $newName); } } } } if(is_dir($argv[1])) { chdir($argv[1]); traverse(getcwd()); } else { die("\n* * *\tError: Cannot open directory ($argv[1])\n"); } echo "\n* * * DONE * * *\n"; ?>
After that just open a terminal window and write:
php mb_conv.php /PATH
After that i found a really good tool that does the same thing, it's called convmv.
If you are using Ubuntu you can open a terminal window and type:
sudo apt-get install convmv convmv --notest -r -f cp1251 -t utf8 DIR
Hope that helps someone out there :).
No comments:
Post a Comment