Here is the situation.. I have one folder in which i have lots of files with name x1.html x2.html x3.html.... and so on.. and i want to change them into y1.html y2.html y3.html and so on.. Is it possible in php??
$prefix = 'y'; foreach (glob('path/to/files/*.html') AS $file) { preg_match('/^.*([0-9]+\.html)/', $file, $filename); rename($file, $prefix . $filename[1]); } PHP: Will take the last part of the old filename (eg: x1.html), and change the rest to the specified prefix. So in this case x becomes y and the rest stays the same. (Tested)
The problem you describe would be solved by recursively calling php's rename() function. The function is described at the php site: rename() . . . . as explained by nico