Help About Rename.php
Started on the old forum in April 2011 · view the original in the archive · old links redirect here
taken from php dot net:
<?php
$path = "my_doc";
function getDirectory( $path = '.', $level = 0 ){
$ignore = array( 'cgi-bin', '.', '..' );
$dh = @opendir( $path );
while( false !== ( $file = readdir( $dh ) ) )
{
if( !in_array( $file, $ignore ) )
{
$spaces = str_repeat( ' ', ( $level * 4 ) );
if( is_dir( "$path/$file" ) )
{
echo "<strong>$spaces $file</strong><br />";
rename($path."\\".$file, strtolower($path."\\".$file));
getDirectory( "$path/$file", ($level+1) );
}
else {
echo "$spaces $file<br />";
rename($path."\\".$file, strtolower($path."\\".$file));
}
}
}
closedir( $dh );
}
getDirectory( $path , 0 )
?>
it renames all files to lower case ... can be easily modified to (im guessing to include site name)
Bro it replies as a Warning: readdir(): supplied argument is not a valid Directory resource in /home/..../public_html/....../renamer.php on line 10 what should i do please help. i have to rename all folder in my hostgator hosting in just one click not one by one. please help...............
Always Help Needy Peoples !!!!!
save this file as renamer.php or whatever u want
<?php
///Posted in Phpadda.in///
// the directory
// './' - is the current directory
// '../' - is the parent directory
// case sensitive
// e.x.: /home/user or c:\files
$dir='./';
// 1 - uppercase all files
// 2 - lowercase all files
// 3 - do not uppercase or lowercase
$up=3;
//rename files that have $w in their filename
//case sensitive
//set to '' if you want to rename all files
$w='';
//do not rename files having $n in their filename
$n='';
//add prefix to files
$prefix='';
//add postfix
$postfix='';
//replace
$replace='Mastiway.com';
$replace_with='Phpadda.in';
//true - traverse subdirectories
//false - do not traverse subdirectories
$tr=true;
////// do NOT change anything below this /////////
set_time_limit(120);
$files=array();
error_reporting(E_ERROR | E_PARSE);
function prep($f,$dir)
{
global $up,$prefix,$postfix,$w,$replace_with,$replace,$n,$files;
if(strpos($f,$n)!==false)
return $f;
$f=str_replace($replace,$replace_with,$f);
if($up==1)
$f=strtoupper($f);
elseif($up==2)
$f=strtolower($f);
$f=$prefix.$f.$postfix;
$files[]=$dir.$f;
return $f;
}
$i=0;
function dir_tr($dir)
{
global $i,$w,$tr,$files;
$dir=rtrim(trim($dir,'\\'),'/') . '/';
$d=@opendir($dir);
if(!$d)die('The directory ' .$dir .' does not exists or PHP have no access to it<br><a target="_blank" href="http://phpadda.in">Need help?</a>');
while(false!==($file=@readdir($d)))
{
if ($file!='.' && $file!='..' && $file!='renamer.php')
{
if(is_file($dir.$file))
{
if($w=='' || (strpos($file,$w)!==false))
{
if(!in_array($dir.$file,$files))
{
rename($dir.$file,$dir.(prep($file,$dir)));
$i++;
}
}
}
else
{
if(is_dir($dir.$file))
{
if($tr)
dir_tr($dir.$file);
}
}
}
}
@closedir($d);
}
dir_tr($dir);
echo '<br>Renamed ' . $i . ' files in directory<br>' . $dir;
echo "<br>You can now delete renamer.php";
?>
put this file in the folder where u kept ur data example:files folder. now run this script and update database and hit THANKS 🙂
yaar this code was working from many days but now i am facing problem please help me. My .htacess is RewriteEngine on RewriteCond %{HTTP_HOST} ^XXXXXXX.com [NC] RewriteRule ^(.*)$ http://www.xxxxxxx.com/$1 [L,R=301]
ErrorDocument 404 / ErrorDocument 403 / ErrorDocument 500 / ErrorDocument 503 /
when i tries to rename files it goes to my site instead of rename files and if i removed error document code it shows as Internal Server Error . Please help me
Always Help Needy Peoples !!!!!