rename mass files from the web directory

Started on the old forum in October 2013 · view the original in the archive · old links redirect here

1 reply · 763 views · started 13 years ago · 1 min read

2 participants
razib Developer · 132 posts #1

Hello

I need a script to mass rename files names from my server if you know any good script for it please suggest the name or if possible share it here 🙂

Thanks in advance!

🦸 Buying mobile traffic, PM me with your traffic details

arpan.rnc Developer · 94 posts #2
<?php

$dir = 'files';
$search = 'text_in_filename_which_you_want_to_rename';
$new ='String_to_replace_the_search_string';
$paths = array();

$i = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));

while($i->valid()) {

    if (!$i->isDot()) {

        $subpath = $i->getSubPath();

        if ($subpath != '') {
            // if inside a subdirectory
            // add the subpath in our array flagging it as false
            if (!array_key_exists($subpath, $paths))
         			$paths[$subpath] = false;

            // check if it's our file
            if (strstr(($i->getSubPathName()),$search)
			  {
			    $n=str_replace($search,$new,$i->getSubPathName());
                            echo $i->getSubPathName().'<br/>';
		            rename($dir.'/'.$i->getSubPathName(),$dir.'/'.$n);				
			   }

    }

    $i->next();
}
}

?>

Write your reply now; next you create a free account (or sign in) and it is posted right away. 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