Answer the question
In order to leave comments, you need to log in
How to move a folder with files and folders to another folder?
Good morning everyone! I have this code
$old_dir = 'test/gg';
$new_dir = 'kl/gg';
mkdir($new_dir, 0755);
$dir = opendir($old_dir);
while($file = readdir($dir))
{
if(is_file($old_dir."/".$file))
{
$cont = file_get_contents($old_dir."/".$file);
file_put_contents($new_dir."/".$file, $cont);
}
}
# Папка с файлами
$old_dir = './kap/';
# Папка в которую перемещаем
$new_dir = './bridun/';
$dir=opendir($old_dir);
$i=1;
while (false !== ($file = readdir($dir))) {
if (is_file($old_dir.$file ) && $file[0] != '...')
{
if (!file_exists($new_dir.$file[0])) {
#Создаём папку по первому символу от названия
mkdir($new_dir.$file[0], 0755); #0777
}
copy($old_dir.$file, $new_dir.$file[0].'./'.$file);
}
#Ограничиваем за один раз
if ($i==500) break;
$i++;
}
closedir($dir);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question