function copyDir( $source, $destination )
{
    // Attempt to create destination dir.
    $status = eZDir::mkdir( $destination );

    // If no success: bail out.
    if ( !$status )
    {
        return false;
    }

    // Get the contents of the directory.
    $entries = getDirEntries( $source );

    // Bail if contents is unavailable.
    if ( $entries == false )
    {
        return false;
    }
    // Else: contents is OK:
    else
    {
        // Copy each and every entry:
        foreach ( $entries as $entry )
        {
            if ( $entry )
            {
                $from = "$source/$entry";
                $to   = "$destination/$entry";

                // Is this a directory? -> special case.
                if ( is_dir( $from ) )
                {
                    $status = copyDir( $from, $to );
                    if (!$status)
                    {
                        return false;
                    }
                }
                // Else: simple file case.
                else
                {
                    $status = copy( $from, $to );
                    if (!$status)
                    {
                        return false;
                    }
                }
            }
        }

    }

    // Phew: if we got this far then everything is OK.
    return true;
}
Пример #2
0
function getdir($dir, $dirsOnly = false, $recurse = array())
{
    if (!$dir) {
        $dir = DSEP;
    }
    $entries = getDirEntries($dir, $dirsOnly);
    if (!count($entries)) {
        return array();
    }
    $dirents = array();
    foreach ($entries as $path => $type) {
        if ($type == 'folder' && count($recurse) && strcasecmp($recurse[0], vbox_basename($path)) == 0) {
            $entry = folder_entry($path, false, true);
            $entry['children'] = getdir($dir . DSEP . array_shift($recurse), $dirsOnly, $recurse);
            array_push($dirents, $entry);
        } else {
            // Push folder on to stack
            if ($type == 'folder') {
                array_push($dirents, folder_entry($path));
                // Push file on to stack
            } else {
                $ext = strtolower(preg_replace('/^.*\\./', '', $file));
                if (count($allowed) && !$allowed['.' . $ext]) {
                    continue;
                }
                array_push($dirents, file_entry($path));
            }
        }
    }
    return $dirents;
}