I’m trying to write a script that’ll rename every file in a directory with a number and regular file extension.
Here’s what I’ve got
[code=php]<?php
$dir = ‘/wampseverwwwexperimentsfiles\’;
# ^^ Give the absolute file path to the folder where your files are, between those quotes.
#forward slash means root, and put 2 backslashes at the end.
$ext = ‘.gif’;
# ^^ Give the extension that you wish the files to have
$allfiles = scandir($dir);
foreach ($allfiles as $number => $name){
if($number != (‘1’ || ‘2’)){ #That bit is so that it doesn’t bother with the root or parent wich was confusing things.
$orginalfile = $dir.$name;
$newfile = $dir.$number.$ext;
/*This is line 15 */ rename($orignalfile,$newfile);
}
}
?>
And this is the error I’ve got
[quote]
Warning: rename(,/wampseverwwwexperimentsfiles .gif) [function.rename]: Permission denied in f:wampseverwwwexperimentsmassrename.php on line 15
As you can tell I’m running this on a WAMP server.
The odd thing is the way that the rename function is reported in the error misses out the original file path, why is this? And more importantly, how can I fix it?