tags:

views:

50

answers:

1

I'm having an array $bundle that stores filenames and directory names.

I'm running through the array with a foreach loop and I want to move them inside of another directory. I'm using the rename method therefore and it works pretty fine with JUST FILES.

However directories with other files in there don't respond to the rename() method.

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

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

}

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

Thank you for your help.

+2  A: 

You will have to get all the filenames in that directory using glob or scandir. Then you would have to loop through them with the rename and move them.

Your other option, if you host allows it, is to use shell_exec and do the mv for linux or copy / xcopy for windows command and move them that way. If you choose the exec route, make sure to secure the input etc to prevent any bad stuff from happening.

Brad F Jacobs