PHP: EXTchange

This script recursively scans through your directories and changes file extensions.

/* ---------------------------------------------------------------
EXTchange 0.01 - File extension changer
(c)2001 Philip Iezzi, http://www.iezzi.ch
last modified : 06/04/2001
This script recursively scans through your directories
and changes file extensions.
--------------------------------------------------------------- */
 
/*-----------------------------------------*/
$old_ext = 'php3';  // your old extension
$new_ext = 'php'; // your new extension
$start_dir = '';   // directory to start
/*-----------------------------------------*/
 
function directoryList ($url) {
	$surl = $url;
	$i = 0;
	if (substr($url,0,1) == '/') $surl = substr($url,1);
	$d = opendir($surl);
	while($entry=readdir($d)) {
		if ($entry != "." && $entry != "..") {
			$outp[$i] = $entry;
			++$i;
		}
	}
	closedir($d);
	return $outp;
}
 
function list_files($path) {
	global $old_ext, $new_ext;
	$path_array = directoryList($path);
	for($i=0; $i < count($path_array); $i++) {
		if ($path > '') $p = '/';
		else $p = '';
		$fd = $path.$p.$path_array[$i];
		if (@is_dir($fd)) list_files($fd);
		else if (preg_match('/\.'.$old_ext.'$/i', $fd)) {
			$fd_new = substr($fd, 0, strlen($fd)-strlen($old_ext)).$new_ext;
			rename ($fd, $fd_new);
			echo $fd.' >>> '.$fd_new.'
			';
		}
	}
}
 
list_files($start_dir);</blockquote>

Comments are closed