Nico baruna

professional web developer

Joomla JFolder class

wat we’ve done yesterday is creating joomla component that can a folder to user component folder while in the instalation process.

first of all we think we need to list all the files on the folder then copy it 1 by 1 using JFile::copy method , we suffers our stupidity for almost 2 hours till then i found JFolder class that has JFolder::copy that can copy all folder’s contents, here’s JFoldfer on it’s action.

function Folder($source , $destination){
    if(JFolder::exists($destination)){
        $failure = ‘[Copy] An error has occurred when copying component file between ‘. $source.’ and ‘.$destination. ’ folder already exsist ‘;
        JError::raiseWarning(E_ERROR, $failure, ”);
        return false;
    }else {
        if(JFolder::create($destination, ‘755’)){
            JFolder::copy($source, $destination,”, TRUE);
            return true;
        }else{
            $failure = ‘[Copy] An error has occurred when copying component file between ‘. $source.’ and ‘.$destination. ’ please check your folder permission’;
            JError::raiseWarning(E_ERROR, $failure, ”);
            }
        }
    }

then  yo can call this function in install even function

function com_install()
{

       $sourceMyprofile = ‘path’;

       $destinationMyprofile = ‘path’;

       if(!copyrecursive($sourceMyProfile , $destinationMyprofile)){
            return false;
        }

}

if there’s any file that not copied please check your path and allt he files are listed on the component xml

Resource : http://docs.joomla.org/How_to_use_the_filesystem_package