mylikes786
Registered Member
- Oct 31, 2013
- 81
- 7
I am using this script to mass rename but i want if the folder exist in directry then it rename all files in folder also
can any one help me
can any one help me
PHP:
<?php
$dir = "/home/yumbolly/public_html/site_files/Movies starts from X" ; // what directory to parse
if ( $handle = opendir ( $dir)) {
print "Directory Handle = $handles\n" ;
print "Files : \n" ;
while ( false !== ($file = readdir($handle))) {
if ( $file != "." && $file != ".." ) {
$isdir = is_dir ( $file ) ;
if ( $isdir == "1" ) {} // if its a directory do nothing
else {
$file_array[] = "$file" ; // get all the file names and put them in an array
print "$file\n" ;
} // closes else
} // closes directory check
} // closes while
}
$arr_count = count( $file_array ) ; // find out how many files we have found so we can initiliase the counter
for ( $counter=0; $counter<$arr_count; $counter++ ) {
print "Array = $file_array[$counter]\n" ; // tell me how many files there are
$new = str_replace ( "FreshMaza.iN", "Submobi.Com", $file_array[$counter] ) ; // now create the new file name
$ren = rename ( "$dir/$file_array[$counter]" , "$dir/$new" ) ; // now do the actual file rename
print "$new\n" ; // print out the new file name
}
closedir ( $handle ) ;
?>