Rename permission

rename('path/oldName',  'path/newName')

The code above changes the old name to new name of the directory when the directory is empty.

When the directory has another directory or file inside the directory, it produces the WARNING like the quote below.

Can I make it change the directory name with your help although the directory has some directories and files ?
Where can I give the Permission for changing the name of a directory?
(I want the directory change and not change any files or idrecotories inside the directory.

Hi,
I’m a noob in this department so I looked up the manual at https://www.php.net/manual/en/function.rename.php

The fourth comment below the description could maybe give some ideas why you get the warning message.

Or could “Permission denied” be caused if you’re not the owner to its content, or could it be caused by a file inside is currently in use?

Just my two cents. :slight_smile:

Correct in a way. “Permission denied” simply means that the file itself cannot be moved because the file permission on that file doesn’t let the server execute it (the function to rename the file). File permissions get a little hazy if you don’t understand how it works.

Assuming this is on a Linux or Mac machine, it’s most likely set to 0644 by default. IIRC, to allow the server to execute the file, it should be set to 0755. I could be wrong.

1 Like

I just tried renaming a directory that had a sub-directory with files files and it worked no problem:

Try this:

<?php
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', '1');

echo '<br>', 
  phpversion();

Output:

7.3.14-6+ubuntu18.04.1+deb.sury.org+1