58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
|
|
function trav($path)
|
|
{
|
|
$handle = opendir($path);
|
|
|
|
while(($child = readdir($handle)) !== false)
|
|
{
|
|
if($child == '.' || $child == '..')
|
|
continue;
|
|
|
|
if(is_dir($path.'/'.$child))
|
|
trav($path.'/'.$child);
|
|
else
|
|
{
|
|
$newname = '';
|
|
// $newname = strtolower($child);
|
|
// $newname = str_replace('.jpg','',$newname);
|
|
// $newname = preg_replace('/[^A-Za-z0-9]+/','_',$newname);
|
|
if(strpos($child,'_gif'))
|
|
{
|
|
$newname = str_replace('_gif.jpg','.gif',$child);
|
|
}
|
|
else if(strpos($child,'_css'))
|
|
{
|
|
$newname = str_replace('_css.jpg','.css',$child);
|
|
}
|
|
else if(strpos($child,'_php'))
|
|
{
|
|
$newname = str_replace('_php.jpg','.php',$child);
|
|
}
|
|
else if(strpos($child,'_mov'))
|
|
{
|
|
$newname = str_replace('_mov.jpg','.mov',$child);
|
|
}
|
|
else if(strpos($child,'_xml'))
|
|
{
|
|
$newname = str_replace('_xml.jpg','.xml',$child);
|
|
}
|
|
else if(strpos($child,'_htm'))
|
|
{
|
|
$newname = str_replace('_htm.jpg','.htm',$child);
|
|
}
|
|
|
|
if(!empty($newname))
|
|
{
|
|
print "Renaming $child to $newname.\n";
|
|
rename($path.'/'.$child, $path.'/'.$newname);
|
|
}
|
|
}
|
|
}
|
|
|
|
closedir($handle);
|
|
}
|
|
|
|
trav('/Users/ben/Sites/d-t-n.org/production');
|
|
|
|
?>
|