Jump to content

What is it wrong in this rename script ?


gunesahmet

Recommended Posts

<?php

$dir='./';
$up=3;
$w='.png';
$n='';
$prefix='';
$postfix='';
$replace='';
$replace_with='';
$tr=false;
set_time_limit(120);
$files=array();
error_reporting(E_ERROR | E_PARSE);
function prep($f,$dir)
{
global $up,$prefix,$postfix,$w,$replace_with,$replace,$n,$files;
if(strpos($f,$n)!==false)
return $f;
$f=str_replace($replace,$replace_with,$f);
if($up==1)
$f=strtoupper($f);
elseif($up==2)
$f=strtolower($f);
$f=$prefix.$f.$postfix;
$files[]=$dir.$f;
return $f;
}
$i=0;
function dir_tr($dir)
{
global $i,$w,$tr,$files;
$dir=rtrim(trim($dir,'\\'),'/') . '/';
$d=@opendir($dir);
if(!$d)die(.$dir . 'Klasorundeki ' ' dosyalarin PHP icin yetkisi yok');
while(false!==($file=@readdir($d)))
{
	if ($file!='.' && $file!='..' && $file!='renamer.php')
	{
		if(is_file($dir.$file))
		{
			if($w=='' || (strpos($file,$w)!==false))
			{
				if(!in_array($dir.$file,$files))
				{
					rename($dir.$file,$dir.(prep($file,$dir)));
					$i++;
				}
			}
		}
		else
		{
			if(is_dir($dir.$file))
			{
				if($tr)
				dir_tr($dir.$file);
			}
		}
	}
}
@closedir($d);
}
dir_tr($dir);
echo '<br> '.$i.' klasorundeki dosyalar yeniden adlandirildi<br>' . $dir;
echo "<br>Simdi renameri silmen gerekiyor ";
?> 

 

Dont rename files this script please help me !!!

Link to comment
https://forums.phpfreaks.com/topic/189486-what-is-it-wrong-in-this-rename-script/
Share on other sites

PHP passes function parameters by value, not by reference, so when you pass your $dir value into the function it works on a  copy of the variable, not the original. So, when the function returns, the original value of $dir will be unchanged.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.