|
Posted by Daniel Schierbeck on 10/04/33 11:11
I've made a small PHP script that renames the files and folders in my
music library, to make them more linux-friendly. I'm running PHP 5.0.3
on version 2.6.9 kernel.
What's happening is that all files and folders are renamed, except for
folders whose names consist of one word only (such as Toto), which is
still with a capital T. Here is the script and the result I'm getting:
<?php
error_reporting(E_ALL | E_STRICT);
header('Content-Type: text/plain');
function clean_filename ($str) {
$str = strtolower($str);
$str = str_replace(' - ', '-', $str);
$str = str_replace(' ', '_', $str);
$str = str_replace('\'', '', $str);
return $str;
}
function parse_dir ($dir_name) {
$dir = opendir($dir_name);
while (false !== ($file = readdir($dir))) {
if ($file != '.' && $file != '..') {
$path_old = $dir_name . $file;
$path_new = $dir_name . clean_filename($file);
echo "renaming $path_old to $path_new... ";
echo rename($path_old, $path_new) ? "done\n" : "failed\n";
if (is_dir($file)) parse_dir($path_old);
}
}
closedir($dir);
}
parse_dir('/shared/music/');
?>
renaming /shared/music/dire_straits to /shared/music/dire_straits... done
renaming /shared/music/johnny_winter to /shared/music/johnny_winter... done
renaming /shared/music/pink_floyd to /shared/music/pink_floyd... done
renaming /shared/music/ten_years_after to
/shared/music/ten_years_after... done
renaming /shared/music/the_doors to /shared/music/the_doors... done
renaming /shared/music/Santana to /shared/music/santana... done
renaming /shared/music/the_jimi_hendrix_experience to
/shared/music/the_jimi_hendrix_experience... done
renaming /shared/music/the_velvet_underground to
/shared/music/the_velvet_underground... done
renaming /shared/music/tim_christensen to
/shared/music/tim_christensen... done
renaming /shared/music/dizzy_mizz_lizzy to
/shared/music/dizzy_mizz_lizzy... done
renaming /shared/music/Toto to /shared/music/toto... done
renaming /shared/music/Cream to /shared/music/cream... done
renaming /shared/music/Filopahpos to /shared/music/filopahpos... done
renaming /shared/music/bob_dylan to /shared/music/bob_dylan... done
renaming /shared/music/dinojax to /shared/music/dinojax... done
renaming /shared/music/red_hot_chili_peppers to
/shared/music/red_hot_chili_peppers... done
renaming /shared/music/peter_frampton to /shared/music/peter_frampton...
done
renaming /shared/music/louis_armstrong-what_a_wonderful_world.mp3 to
/shared/music/louis_armstrong-what_a_wonderful_world.mp3... done
As you can see, the rename() returns TRUE, but it doesn't rename the folder.
I hope you guys can help me out, because otherwise I'll have to do it
manually (which I'm too lazy to even consider.)
Daniel
[Back to original message]
|