Last Updated: May 31, 2021
· simon_hen

Rename folder in PHP

Sometimes, for any reason, we need to rename folder's name in PHP (like I do for system folder in EE.).

There is a function in php called <a href="">rename</a>. This function works perfectly with files.

The problems (in my case) begin with folder's rename, when I want to do it, I'm using :


Now,when I'm using this, I have the next error :

Warning: rename(/myoldfolder,/mynewfolder) [function.rename]: Permission denied in /Applications/MAMP/htdocs/config_dev/configure.php on line 26

This is not a real permission problem around here because I have the right to do it.

But, how ?

The idea is to give an absolute link and not a relative link like this :


And, voila ! Everything should works perfectly (like in my place) !


This piece of code is going to give your current folder where the code is executed like this :


Hope it helps some of you !


1 Response
Add your response

i am using this rename function with some editing like
saving folders name in variables
following is my code:


$oldfoldername= $row['facility_name'];

old folder name is coming from D.B.


new folder name is a combination of date time and some alphabets.

i am getting following error :

Warning: rename(C:\xampp\htdocs\restaurantd,C:\xampp\htdocs\restaurantback%05/20/2014 08:21:34 %d) [function.rename]: The system cannot find the file specified. (code: 2) in C:\xampp\htdocs\restaurant\DeleteUser.php on line 31.

i need help.
thanx in advance :)

over 1 year ago ·