PHP: moving directories with content?

I have an array $bundlethat stores file names and directory names.

I am running an array with a foreach loop, and I want to move them inside another directory. Therefore, I use the rename method and it works very well with JUST FILES.

However, directories with other files there do not respond to the method rename().

$folder =  'files';
foreach ($bundle as $value) {
    $ext = pathinfo($value, PATHINFO_EXTENSION);
    if ($ext != "") { //if $value has no suffix it a fil
        rename(PATH . '/' .$value, $folder . '/' . $value);
    }

    if ($ext == "") { // it a folder/directory
        //rename doesn't work for directories with contents
        //what method should i use here???
    }

}

I know that a method is pathinfo()not the best way to find out if it is a directory or not, however for my small project this is normal. I just need to know how I can move any directory with all the contents to the "files" folder.

Thank you for your help.

+3
source share
1 answer

, glob scandir. .

, , shell_exec mv linux copy/xcopy windows . exec, , .., - .

+4

Source: https://habr.com/ru/post/1762555/


All Articles