opendir trying to find paths which don't exist now because they're renamed

I am setting up renaming functionality a part of a crud system for dirs, and right setting up a process to rename sub-directory of an uploads directory and the renaming process is working meaning dirs are being renamed accordingly yet I am getting error codes from opendir. Apparently the paths are not being found because they're paths that had been renamed. Not sure how to remedy this problem which is the million dollar question??

controller:

private function _edify_dirs_recursive($targets, $new_dirs)
{
    $targets = rtrim(preg_replace(array("/\\\\/", "/\/{2,}/"), "/", $targets), "/");
    $new_dirs = rtrim(preg_replace(array("/\\\\/", "/\/{2,}/"), "/", $new_dirs), "/");
    $explode_targets = explode(',',$targets);
    $explode_new_dirs = explode(',',$new_dirs);

    foreach($explode_targets as $target_keys):
        $dirs_obsolete = "./uploads/$target_keys";
        foreach($explode_new_dirs as $new_dirs_keys):
            $dirs_new = "./uploads/$new_dirs_keys";
            $chid_generator = @rename($dirs_obsolete,$dirs_new);
            if($dhandle = @opendir("./uploads/$target_keys"))
            {
                while(FALSE !== ($entry = @readdir($dhandle)))
                {
                    { true; }
                }
                //closedir must be within if logic
                @closedir($dhandle);
            }
        endforeach;
    endforeach;
}

Answers


Since you've just renamed ./uploads/$target_keys to ./uploads/$new_dirs_keys, you shouldn't be trying to opendir("./uploads/$target_keys"), but opendir("./uploads/$new_dirs_keys").


Need Your Help

Setting up full page ads

ios uiviewcontroller ios7 admob ads

I am using Admob Mediation service with an Interstitial ad type for a full page ad.

Assistance With KeyEvent

java swing key coordinates keyevent

I am making a platformer game for a class project and so far all I have been able to do is add the chicken character to the game. I need to be able to have him move forward on the press of "D" or r...