I have a directory structure like so:
.
├── uploads
| ├── 1
| | ├── example.jpeg
| | └── example.jpeg
| ├── 2
| | └── example.jpeg
| ├── 3
| | ├── example.jpeg
| | ├── example.jpeg
| | └── example.jpeg
I wish to rename all the directories in my firectory uploads (in my example these are called 1, 2 and 3). I want to rename all of these directories based on their current name. For example, I want 1 to become 1asd, 2 to 2asd and 3 to 3asd. I have looked for similar questions and found This one (which although the question seems similar is actually about something else) and this one, which is about renaming files.
I tried:
if ($handle = opendir('../path/to/uploads')) {
while (false !== ($fileName = readdir($handle))) {
$newName = $fileName.'asd';
rename($fileName, $newName);
}
closedir($handle);
}
This doesn't work because all $filename is always .. My guess is because it's about directories and not files. How do I target the directories instead?
side-note1: the directories I wish to rename contain files which I do not want to lose/delete. In my example they are all called example.jpeg.
side-note2: the path to my uploads directory is correct, I tested this.