I’m an old-fashioned IT guy: in filenames I prefer the standard ASCII character set, no spaces, no weird international characters and no meter long names. Before writing a directory to a DVD:
<?php
function cdRename($path, $maxlength) {
$pi = pathinfo($path);
$ext = isset($pi['extension']) ? $pi['extension'] : FALSE;
$fn = $pi['filename'];
$fn = substr($fn, 0, $maxlength);
$fn = str_ireplace(//iso 8859-1 only :((
array('á', 'à', 'ã', 'â', 'é', 'è', 'î', 'í', 'ú', 'u', 'ö', 'õ', 'ô'),
array('a', 'a', 'a', 'a', 'e', 'e', 'i', 'i', 'u', 'u', 'o', 'o', 'o'), $fn);
$npath = $pi['dirname'] . DIRECTORY_SEPARATOR . $fn . ($ext ? '.'.$ext : '');
if ($npath != $path) rename($path, $npath);
}
$it = new RecursiveDirectoryIterator('./');
// RecursiveIteratorIterator - 0: LEAVES_ONLY, 1: SELF_FIRST, 2: CHILD_FIRST
foreach (new RecursiveIteratorIterator($it, 2) as $path) cdRename($path, 170);
?>
This is a PHP cli (shell) script, it truncates filenames (without touching the extension) and removes some international characters, which may pose problems when transferred to ntfs/fat/samba/ext3 etc. Unfortunately PHP is still a crap and if you save this script in UTF-8 then it will not work (at least it did not work for me on ntfs and php 5.2.6), so so far one can only replace iso 8859-1 characters; hope this will change with version 6. The script can also rename directories, since the iterator takes children items first – hope someone finds this useful.