Suppose, we have to change some keyword within a folder for all files name.
For that I have written a small program, Its take a folder name and take all the files's name of the folder in the array, and we replace the specific keyword with the word, we want there. 
Follow the program for the code, you just need to change the first three variable of the code.











See Live Example here

<?php

$dir = 'rename4folder';  
// folder path within this file, If are nor sure about the location, just use the full Physical URL of the folder

$replacekeyword  = 'replace';  // name to be replaced

$replacewith  = 'with';  // name with this the name replacerd
$files = scandir($dir);
if(is_array($files))
{
foreach($files as $single)
{
$newsingle = str_replace($replacekeyword,$replacewith,$single);
if(($single!=".")&&($single!=".."))
{
$dothis = 1;
}
if($dothis)
{
if(rename($dir.'/'.$single, $dir.'/'.$newsingle))
{
echo "<br/>".$single." renamed to ".$newsingle;
} else {
echo "<span style='color:#cc0000'><br/>".$single." not renamed to ".$newsingle."</span>";
}
}
}
}
?>
24 Mar 2015

Post a Comment

Emoticon
:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
Top