Я хочу переименовать все файлы в папку со случайными числами или символами.переименовать все файлы в папке со случайным именем
Это мой код:
$dir = opendir('2009111');
$i = 1;
// loop through all the files in the directory
while (false !== ($file = readdir($dir))) {
// do the rename based on the current iteration
$newName = rand() . (pathinfo($file, PATHINFO_EXTENSION));
rename($file, $newName);
// increase for the next loop
$i++;
}
// close the directory handle
closedir($dir);
, но я получаю эту ошибку:
Warning: rename(4 (2).jpg,8243.jpg): The system cannot find the file specified
Это звучит как проблема [XY] (https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Чего вы пытаетесь достичь, делая это? И какова ошибка, которую вы получаете? – Chris
1. * но эта ошибка *, какая ошибка? 2. Нет смысла использовать переменную '$ i' в цикле' while() '. –
Предупреждение: rename (4 (2) .jpg, 8243.jpg): Система не может найти указанный файл ... – dexter