NameSilo

PHP Help Needed

Spaceship Spaceship
Watch

snike

Established Member
Impact
3
I was looking for a way that a php script in a folder could renamed all the files in another folder from 100 to like 400. like each file name increments. can this be done in php? if so, how?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
I think I have understood what you mean.

The following does what I believe you require:-

PHP:
<?php
$folder = '/home/domain/public_html/folder/';
$start = 1;
if (is_dir($folder))
{
	$handle = opendir($folder);
	while (false != ($file = readdir($handle)))
	{
		if ($file == '.' OR $file == '..')
		{
			continue;
		}
		rename($folder.$file, $folder.$start);
		echo $file.' has been renamed too '.$start.'<br>';
		$start++;
	}
	closedir($handle);
}
else
{
	echo 'Folder Does Not Exist';
}
?>

Remember tho test it on files that you do not care about. Also remember to change the path $folder contains, it should be the full server path to the folder with the files you wish to rename. Also ensure you chmod the folder so that php can write to it.

The script starts at 1 and increments from there. If you wish you can change that by changing the content of the $start variable.
 
1
•••
thank you!
 
0
•••

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back