Help About Rename.php

Started on the old forum in April 2011 · view the original in the archive · old links redirect here

11 replies · 1,147 views · started 15 years ago · 1 min read

5 participants
zong11 Developer · 98 posts #1

how to use rename php in order to rename multiple files from hosting.

Always Help Needy Peoples !!!!!

something else Fellow · 2,296 posts #2

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)

zong11 Developer · 98 posts #3

thanks but not working........errror on page

Always Help Needy Peoples !!!!!

something else Fellow · 2,296 posts #4

getDirectory( $path , 0 )

is ment to be:

getDirectory( $path , 0 );

zong11 Developer · 98 posts #5

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 !!!!!

Pflash Developer · 170 posts #6

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 🙂

zong11 Developer · 98 posts #7

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 !!!!!

Pflash Developer · 170 posts #8

Which script u using? And what err0r u getting?

zong11 Developer · 98 posts #9

i am using modified sea script and when i tried to laod rename php it redirects to site

Always Help Needy Peoples !!!!!

zong11 Developer · 98 posts #11

done friend but not working

Always Help Needy Peoples !!!!!

djdevil89 Senior · 287 posts #12

some hosts dont allow 777 this gives an internal server error try 755

foreach ($_SERVER as $server => $value)
{
echo "$server is $value<br />";
}

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close