Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

PHP Help Needed

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
thank you!
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back